JDBC连接mysql步骤
步骤
1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
2.获得连接
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");
其中三个参数分别对应url ,username和password
3.需要执行的sql语句
String sql = "....";
4.创建执行对象
Statement stat = con.createStatement(sql);
5.执行
boolean b = stat.execute();
6.释放资源
stat.close();
con.close();
上述步骤其实存在sql注入问题