vagabond1-1983 / blog

My tech blog for achieve
GNU General Public License v2.0
2 stars 0 forks source link

【JavaEE之JDBC】JDBC基本步骤 #26

Open vagabond1-1983 opened 8 years ago

vagabond1-1983 commented 8 years ago

1.Load the Driver,向DriverManager注册 ①.Class.forName(“该Driver的名字”)或者是Class.forName(“该Driver的名字”).newInstance()或者直接new这个Driver ②.实例化时自动向DriverManager注册,不需要再调用DriverManager.registerDriver方法 2.Connect to the DataBase ①.DriverManager.getConnection() 3.Excute the SQL ①.Connection.CreateStatement() //sql注入问题,应该用PrepareStatement ②.Statement.executeQuery() ③.Statement.executeUpdate() 4.Retrieve the result data Retrieve (检索储存的信息) ①.循环取得结果 while(rs.next()) 5.Show the result data ①.将数据库中的各种类型转换为java中的类型,用get方法 6.Close (后打开的先关) ①.close the ResultSet ②.close the Statement ③.close the Connection