各位高手! 小弟我刚接触JSP所以困难重重,望能帮助我! 这是我的环境变量设置 CLASSPATH C:\j2sdk1.4.2_07\lib\tools.jar;C:\j2sdk1.4.2_07\lib\mm.mysql-2.0.4-bin; C:\jakarta-tomcat-5.0.30\common\classes;C:\jakarta-tomcat-5.0.30\common\lib; JAVA_HOME C:\j2sdk1.4.2_07 TOMCAT_HOME C:\jakarta-tomcat-5.0.30 以下是SQL(是叫表吧?): use jspdev; create table book(bookId varchar(50),bookName varchar(50),publisher varchar(100),price float,constraint pk_book primary key(bookId)); insert into book values('001-22-23-1','jsp 应用开发详解','电子工业出版社',59.0); (jspdev是用户名) 以下是连接MYSQL 的编程: <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"%> <html> <body> 以下是从Mysql数据库读取的数据:<hr> <table border=1> <tr><td>id</td><td>书名</td><td>出版社</td><td>价格</td></tr> <%
Class.forName("org.gjt.mm.mysql.Driver").newInstance(); Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://127.0.0.1/jspdev","root",""); Statement stmt=con.createStatement(); ResultSet rst=stmt.executeQuery("select * from book;"); while(rst.next()) { out.println("<tr>"); out.println("<td>"+rst.getString("bookId")+"</td>"); out.println("<td>"+rst.getString("bookName")+"</td>"); out.println("<td>"+rst.getString("publisher")+"</td>"); out.println("<td>"+rst.getFloat("price")+"</td>"); out.println("</tr>"); } file://关闭连接、释放资源 rst.close(); stmt.close(); con.close(); %> </table> </body> </html> 请求各位高手协助!!!!小弟谢了!