日期:2014-05-16  浏览次数:20327 次

jsp与SQL连接问题,烦啊,高手指点
代码如下,可是一直报错

<%@page contentType="text/html;charset=gb2312"%>  
<%@page import="java.util.*"%>  
<%@page import="java.sql.*"%>  
  <%  
  try{  
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();  
   
  Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://SqlServer2000:1433;DatabaseName="pubs";User="sa";Password="");  
  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
  String sql="select * from jobs";  
  ResultSet rs=stmt.executeQuery(sql);  
  rs.next();  
  out.println(rs.getString(1));  
  out.println("Ok");  
  }catch(Exception e)  
  {  
  out.println(e.getMessage());  
  out.println("err");  
  }  
  %>

 数据库名、用户名、密码都正确,lib下也加载了msbase.jar/mssqlserver.jar/msutil.jar包.  
  总是有以下错误:
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: 8 in the jsp file: /index.jsp
Syntax error, insert ")" to complete MethodInvocation
5: try{  
6: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();  
7:  
8: Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://SqlServer2000:1433;DatabaseName="guan";User="sa";Password="");  
9: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
10: String sql="select * from guanrong";  
11: ResultSet rs=stmt.executeQuery(sql);  


An error occurred at line: 8 in the jsp file: /index.jsp
Syntax error, insert ";" to complete LocalVariableDeclarationStatement
5: try{  
6: Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();  
7:  
8: Connection conn=DriverManager.getConnection("jdbc:microsoft:sqlserver://SqlServer2000:1433;DatabaseName="guan";User="sa";Password="");  
9: Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);  
10: String sql="select * from guanrong";  
11: ResultSet rs=stmt.executeQuery(sql);  


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)