首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

急jsp连接sqlsever时的有关问题

2013-09-11 
急!jsp连接sqlsever时的问题在不连接数据库时,jsp能运行,但连接数据库时会出现如下的问题:HTTPStatus500-t

急!jsp连接sqlsever时的问题
在不连接数据库时,jsp能运行,但连接数据库时会出现如下的问题:
HTTP   Status   500   -

type   Exception   report

message

description   The   server   encountered   an   internal   error   ()   that   prevented   it   from   fulfilling   this   request.

exception

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

An   error   occurred   at   line:   5   in   the   jsp   file:   /test.jsp
Syntax   error   on   tokens,   delete   these   tokens
2:   <%@   page   import= "java.sql.* "%>  
3:   <html>   <head> </head>
4:   <body>  
5:   <%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();  
6:   String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ";    
7:   String   user= "sa ";  
8:   String   password= "1233651406wh ";  


An   error   occurred   at   line:   5   in   the   jsp   file:   /test.jsp
Syntax   error,   insert   "; "   to   complete   Statement
2:   <%@   page   import= "java.sql.* "%>  
3:   <html>   <head> </head>
4:   <body>  
5:   <%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();  
6:   String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ";    
7:   String   user= "sa ";  
8:   String   password= "1233651406wh ";  


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:435)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:299)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Apache   Tomcat/5.5.23   logs.
请问这是怎么回事,我的测试程序如下
<%@   page   contentType= "text/html;charset=gb2312 "%>  
<%@   page   import= "java.sql.* "%>  
<html>   <head> </head>
<body>  
<%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ").newInstance();  
String   url= "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ";    
String   user= "sa ";  
String   password= "1233651406wh ";  
Connection   conn=   DriverManager.getConnection(url,user,password);  
Statement   stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  


String   sql= "select   *   from   NAME ";  
ResultSet   rs=stmt.executeQuery(sql);  
您的第一个字段内容为: <%=rs.getString(1)%>  
<%out.print( "数据库操作成功,恭喜你 ");%>  
<%rs.close();  
stmt.close();  
conn.close();  
%>  
</body>  
</html>

[解决办法]
String sql= "select * from NAME ";
ResultSet rs=stmt.executeQuery(sql);

if(rs.next()){ //必需先这样.因为第一次它指在第一条记录的前面.
%>
您的第一个字段内容为: <%=rs.getString(1)%>
<%
}
ut.print( "数据库操作成功,恭喜你 ");%>
<%rs.close();
stmt.close();
conn.close();
%>
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html

热点排行