读书人

jsp连接数据库有关问题?

发布时间: 2013-09-11 18:34:25 作者: rapoo

jsp连接数据库问题????

刚装好TOMCAT6.0 连接MYSQL测试没问题,JDK6.0
可把java.sql.删掉就才出现
在连接就出现

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 33 in the jsp file: /d.jsp
The type Statement is ambiguous
30: out.print( "数据库连接成功! ");
31:
32: out.print( " <br> ");
33: Statement statement = conn.createStatement();
34:
35: String sql= "SELECT * FROM "+ tableName;
36:


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


String url= "jdbc:mysql://localhost/ "+dbName+ "?user= "+userName+ "&password= "+userPwd;

Class.forName( "com.mysql.jdbc.Driver ").newInstance();


java.sql.Connection conn=DriverManager.getConnection(url);
out.print( "数据库连接成功! ");

out.print( " <br> ");
java.sql.Statement statement = conn.createStatement();

String sql= "SELECT * FROM "+ tableName;

java.sql.ResultSet rs = statement.executeQuery(sql);


[解决办法]
The type Statement is ambiguous
说明你的引用又问题,必须用java.sql.*中的类
Statement在其他的的路径下也存在,如java.bean.*中,看看你有没有import这个,去掉就可以了
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

读书人网 >Java Web开发

热点推荐