public 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) {
}
});
怎么使输入查询信息后点击这个按钮使数据库信息显示出来