首先先创建一个执行SQL语句的方法:
public static boolean executeSql(String sql){
String url = "jdbc:mysql://localhost:3306/lending";//数据源(mysql)的连接地址
String user = "root";//用户名
String password = "root";//用户密码
boolean success = false;
Connection con = null;
PreparedStatement ps = null;
try {
//加载驱动程序
Class.forName("com.mysql.jdbc.Driver");
//获取连接
con = DriverManager.getConnection(url, user, password);
ps = con.prepareStatement(sql);
if(ps.executeUpdate() > 0){
success = true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
//关闭资源
if(rs !=null){
rs.close()