向書本學(xué)習(xí),還要向?qū)嵺`學(xué)習(xí)、向生活學(xué)習(xí)。消化已有知識,
而且要力求有所發(fā)現(xiàn)、有所發(fā)明、有所創(chuàng)造
2019/3/27 9:48:33
1 裝載數(shù)據(jù)庫的JDBC驅(qū)動程序
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);
2 建立與數(shù)據(jù)庫的連接
Connection con=java.sql.DriverManager.getConnection(JDBC URL,用戶名,密碼) ;
3 創(chuàng)建Statement或PrepareStatement對象
Statement stmt = con.createStatement();
PrepareStatement prepStmt =con.prepareStatement(selectStatement);
4 調(diào)用SQL語句
String sql = “select id,name,title,price from books where=‘Tom’ and price=40”;
ResultSet rs=stmt.executeQuery(sql);
5 訪問ResultSet
while(rs.next())
{
String col1 = rs.getString(1);
String col2 = rs.getString(2);
String col3 = rs.getString(3);
float col4 = rs.getFloat(4);
}
6 依次關(guān)閉ResultSet,Statement,Connection對象
rs.close();
stmt.close();
con.close();
深圳市南山區(qū)南山街道南海大道西桂廟路北陽光華藝大廈1棟4F、4G-04
咨詢電話:136 8237 6272
大客戶咨詢:139 0290 5075
業(yè)務(wù)QQ:195006118
技術(shù)QQ:179981967