- 通过编写数据库工具类,将数据库的连接、查询、更新操作编写成特定的方法;
- 使用PreparedStatement语句;
- 传递数组形成SQL语句;
public class DBUtil {
private static Connection conn;
private static PreparedStatement ps;
private static ResultSet rs;
public static Connection getConnection(){
String Url = "jdbc:mysql://localhost:3306/smp";
String User = "root";
String Passwd = "123123";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(Url, User, Passwd);
return conn;
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
} catch (SQLException e) {
e.printStackTrace();
return null;
}
}
publ