|
JDBC方式调用数据库相关说明 |
|
作者:客服中心 文章来源:中国万网 点击数: 更新时间:2008-4-23 |
|
1 装载数据库的JDBC驱动程序 Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); 2 建立与数据库的连接 Connection con=java.sql.DriverManager.getConnection(JDBC URL,用户名,密码) ; 3 创建Statement或PrepareStatement对象 Statement stmt = con.createStatement(); PrepareStatement prepStmt =con.prepareStatement(selectStatement); 4 调用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 依次关闭ResultSet,Statement,Connection对象 rs.close(); stmt.close(); con.close(); |
返回上一页 |
|
|
|
相关文章: 没有相关文章 |