主题搜索 全文搜索
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();
上一个文章:在Tomcat下如何增加虚拟路径
下一个文章:JSP预定义变量的使用
相关文章:
香港服务器Linux系统下三种方式设置环境变量-八联网络
香港服务器Linux操作系统睡眠和休眠的二种方式-八联网络
香港服务器五条强化SSH安全的建议-八联网络
香港服务器Linux系统以form表单形式上传文件-八联网络
香港服务器Linux系统如何清理磁盘-八联网络
香港服务器Linux系统xlsatom命令如何使用?-八联网络