一个只会打Dota2的胖子
2016-03-03 04:20新人求解 java GUI写的界面 按钮这点不会写
1public class Jdbc {
public static Connection getConn(){
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test"", "root", "root");
if (!conn.isClosed()) {
System.out.println("成功连接数据库");
java.sql.PreparedStatement ps = conn.prepareStatement("select * from users");
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.println("id : " + rs.getInt(1) + " name : " + rs.getString(2) + " role : " + rs.getString(3)
- " password: " + rs.getString(4)); }}} catch (Exception e) { e.printStackTrace(); } return conn; } }
这是连接数据库的代码
JButton button_3 = new JButton("查询");
button_3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
怎么使输入查询信息后点击这个按钮使数据库信息显示出来
- 点赞
- 回答
- 收藏
- 复制链接分享
5条回答
为你推荐
- 新人求解 java GUI写的界面 按钮这点不会写
- 数据库
- java
- gui
- jdbc
- 5个回答