一、加载驱动
Class.forName("com.mysql.jdbc.Driver");
二、准备连接字段
String url = "jdbc:mysql://localhost3306:数据库名“;
String user = "root";
String pwd = ".....";
三、获取连接对象
Connection con = DriverManager.getConnection(url,user,pwd);
四、编写sql语句
String sql = "select * from 表名”
五、获取处理对象
PreStatement pre = con.creatPreStatement();
六、处理结果
查询:ResultSet re = pre.excuteQuerry();
输出:while(re.next){
Sysout.out.pritln(re.getString("name")+re.getInt("ID")
}
增删改:int count = pre.excuteUpdate();
七、关闭资源
re.close();
pre.close();
con.close();