java 按钮响应事件
来源:百度知道 编辑:UC知道 时间:2024/06/21 21:00:07
写一个和你数据库里的数据一样的映射类,写一个数据库操作类 例如:
package Ex7_2;
import java.sql.*;
public class DBOperator<cmd> {
String driver="com.mysql.jdbc.Driver";
String url="jdbc:mysql://127.0.0.1:3306/Ex7_2";
String user="root";
String pwd="1234";
public Connection createConnection() throws SQLException{
try {
Class.forName(driver);
} catch (ClassNotFoundException e) {
System.out.print("创建连接时用户密码出错或者连接出错");
e.printStackTrace();
}
return DriverManager.getConnection(url,user,pwd);
}
public ResultSet executeQuery(String sql) throws SQLException{
Connection con=createConnection();
Statement cmd=con.createStatement();
return cmd.executeQuery(sql);
}
public void executeUpdate(String sql) throws SQLException{
Connection con=createConnection();
Statement cmd=con.createStatement();
cmd.execute