数据库小问题
代码:
<%@ page contentType= "text/html;charset=GB2312 "%>
<%@ page import= "java.sql.* "%>
<html>
<body>
<%
Connection con;
Statement sql;
ResultSet rs;
try{Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
}
catch(
ClassNotFoundException e){}
con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");
sql=con.createStatement();
rs=sql.executeQuery( "select * from user ");
while(rs.next())
{
out.print(rs.getString(1));
out.print(rs.getString(2));
out.print(rs.getString(3));
}
con.close();
}
catch(
SQLException e1){}
%>
</body>
</html>
报错:
org.apache.jasper.JasperException: Unable to compile class for JSP:
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:415)
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:308)
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)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.10 logs.
------解决方案--------------------try{Class.forName( "sun.jdbc.odbc.JdbcOdbcDriver ");
}
catch(Class
NotFoundException e){}
//这里缺了try了...或者整合到前面那个try catch块中去
try {
con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");
sql=con.createStatement();
rs=sql.executeQuery( "select * from user ");
while(rs.next())
{
out.print(rs.getString(1));
out.print(rs.getString(2));
out.print(rs.getString(3));
}
con.close();
}
catch(SQLException e1){}
------解决方案-------------------- try{//try上也不行吗?
con=DriverManager.getConnection( "jdbc:odbc:sun ", "sa ", " ");
sql=con.createStatement();
rs=sql.executeQuery( "select * from user ");
while(rs.next())
{
out.print(rs.getString(1));
out.print(rs.getString(2));
out.pr