我有WEB-INF\lib\mysql-connector-java-3.1.14-bin.jar文件代码如下:
<%@ page contentType="text/html; charset=gb2312" %><%@ page language="java" %><%@ page import="com.mysql.jdbc.Driver" %><%@ page import="java.sql.*" %><%//驱动程序名String driverName="com.mysql.jdbc.Driver";//数据库用户名String userName="root";//密码String userPasswd="123456";//数据库名String dbName="test";//表名String tableName="login";//联结字符串String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;Class.forName("com.mysql.jdbc.Driver").newInstance();Connection connection=DriverManager.getConnection(url);Statement statement = connection.createStatement();String sql="SELECT * FROM "+tableName;ResultSet rs = statement.executeQuery(sql); //获得数据结果集合ResultSetMetaData rmeta = rs.getMetaData();//确定数据集的列数,亦字段数int numColumns=rmeta.getColumnCount();// 输出每一个数据值out.print("id"); out.print("|");out.print("num");out.print("<br>");while(rs.next()) {out.print(rs.getString(1)+" "); out.print("|");out.print(rs.getString(2));out.print("<br>"); } out.print("<br>");out.print("数据库操作成功,恭喜你"); rs.close(); statement.close(); connection.close(); %>
出错提示
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 9 in the jsp file: /jsp-mysql.jsp
Generated servlet error:
String literal is not properly closed by a double-quote
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause org.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 9 in the jsp file: /jsp-mysql.jsp
Generated servlet error:
String literal is not properly closed by a double-quote
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.请各位大吓指点,谢谢