同) package trade; import java.sql.*; public class conndb { String url="jdbc:inetdae:localhost";String login="user"; String password = "xxxxxx"; String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";String sConnStr = "jdbc:odbc:Dsnmysql"; Connection conn = null; ResultSet rs = null; public conndb() {try {Class.forName(sDBDriver); Connection conn = DriverManager.getConnection(url,login,password);} catch(java.lang.ClassNotFoundException e) {System.err.println("conndb(): " + e.getMessage ());}} Public/ResultSet/executeQuery(String/sql)/{rs=null;try{conn=DriverManager.getConnection(sConnStr); Statement stmt = conn.createStatement();rs = stmt.executeQuery(sql); } catch(SQLException ex) {System.err.println("aq.executeQuery: " + ex.getMessage());} return rs; }} 然后用javac编译conndb.java生成与其同目录的conndb.class文件,在form_cl.jsp文件中加入如下标签即可建立与数据库的连接 获去表单提交的数据: String data1=request.getParameter("ptwbk"); String data2=request.getParameter("mmwbk ") String data3=request.getParameter("gdwbk ") String data4=request.getParameter("dxk ") String data5=request.getParameter("fxk ") String data5=request.getParameter("lbk ") 语句对数据库进行操作 查询数据记录: String sql="select * from tab lename"; connbean.executeQuery(sql); 增加数据记录: String sql="insert into tablename values('" + data1 + "','" +data2 +"','" +data3 + "','" + data4+ "'+"','" + data5+"','" + data6+'")";connbean.executeQuery(sql); 更改某条数据记录: String sql="update tablename set data1='" + ptwbk + "',data2='" + mmvbk + "',data3='" +gdwbk + "' where ID='" + num + "'" ;connbean.executeQuery(sql) 删除某条数据记录: String sql="delete from tablename where ID='" +num+ "'" ; connbean.executeQuery(sql); ;将SQL语句处理的数据结果输出 ResultSet rs = connbean.executeQuery(sql); While (rs.next()) {out.print("
"+rs.getString("ptwbk")+"
");out.print("
"+ rs.getString("mmvbk") + "
");out.print("
" + rs.getString("gdwbk") + "
"); out.print("
" + rs.getString("dxk") + "
");out.print("
" + rs.getString("fxk") + "
");out.print("
" + rs.getString("lbk") + "
");} 关闭数据库: rs.close();
上一页 [1] [2] [3] [4] [5] [6] 下一页
电子商务网站平台3P设计技术与网络数据库 第5页下载如图片无法显示或论文不完整,请联系qq752018766