Z
zlc_168
Unregistered / Unconfirmed
GUEST, unregistred user!
这个问题已经有4、5天未解决了。那就是从JSP中连接sql server数据库,详细资料如下:
jdk:jdk1.40;
apache:apache_2.0.43;
tomcat:tomcat-4.1.24;
sql server 2000 driver for jdbc;
安装好以上组件后,输入http://localhost和http://localhost:8080均可见到正确的
运行画面。并且已经将sql server 2000 driver for jdbc中三个jar文件:
mabase.jar、msutil.jar、mssqlserver.jar拷贝到jdk/bin目录下,相应的path和
classpath均已设置,但是一运行以下代码就出错,请哪位大侠给看看,如解决,
本人将给200分,源码:
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<%@ page language="java" import="java.sql.*" contentType="text/html;charSet=gb2312"%>
<%String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://zhy:1433;DatabaseName=pubs";
String user="sa";
String password="";
String sqlstr="select * from jobs";
try{
Class.forName(driver).newInstance();
Connection conn=DriverManager.getConnection(url,user,password);
}
catch(Exception e){
out.println(e.toString());
}
try{
Statement lstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=lstmt.executeQuery(sqlstr);
}
catch(Exception e){
out.println(e.toString());
}
while (rs.next()){
out.println("<tr><td>"+rs.getString("job_desc")+"</tr></td>");
}
conn.close();
%>
%>
</body>
</html>
出错信息:
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: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:62: cannot resolve symbol
[javac] symbol : variable conn
[javac] location: class org.apache.jsp.query_jsp
[javac] Statement lstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
[javac] ^
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:68: cannot resolve symbol
[javac] symbol : variable rs
[javac] location: class org.apache.jsp.query_jsp
[javac] while (rs.next()){
[javac] ^
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:69: cannot resolve symbol
[javac] symbol : variable rs
[javac] location: class org.apache.jsp.query_jsp
[javac] out.println(""+rs.getString("job_desc")+"");
[javac] ^
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:71: cannot resolve symbol
[javac] symbol : variable conn
[javac] location: class org.apache.jsp.query_jsp
[javac] conn.close();
[javac] ^
[javac] 4 errors
jdk:jdk1.40;
apache:apache_2.0.43;
tomcat:tomcat-4.1.24;
sql server 2000 driver for jdbc;
安装好以上组件后,输入http://localhost和http://localhost:8080均可见到正确的
运行画面。并且已经将sql server 2000 driver for jdbc中三个jar文件:
mabase.jar、msutil.jar、mssqlserver.jar拷贝到jdk/bin目录下,相应的path和
classpath均已设置,但是一运行以下代码就出错,请哪位大侠给看看,如解决,
本人将给200分,源码:
<html>
<head>
<title>New Page 1</title>
</head>
<body>
<%@ page language="java" import="java.sql.*" contentType="text/html;charSet=gb2312"%>
<%String driver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String url="jdbc:microsoft:sqlserver://zhy:1433;DatabaseName=pubs";
String user="sa";
String password="";
String sqlstr="select * from jobs";
try{
Class.forName(driver).newInstance();
Connection conn=DriverManager.getConnection(url,user,password);
}
catch(Exception e){
out.println(e.toString());
}
try{
Statement lstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=lstmt.executeQuery(sqlstr);
}
catch(Exception e){
out.println(e.toString());
}
while (rs.next()){
out.println("<tr><td>"+rs.getString("job_desc")+"</tr></td>");
}
conn.close();
%>
%>
</body>
</html>
出错信息:
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: -1 in the jsp file: null
Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:62: cannot resolve symbol
[javac] symbol : variable conn
[javac] location: class org.apache.jsp.query_jsp
[javac] Statement lstmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
[javac] ^
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:68: cannot resolve symbol
[javac] symbol : variable rs
[javac] location: class org.apache.jsp.query_jsp
[javac] while (rs.next()){
[javac] ^
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:69: cannot resolve symbol
[javac] symbol : variable rs
[javac] location: class org.apache.jsp.query_jsp
[javac] out.println(""+rs.getString("job_desc")+"");
[javac] ^
[javac] D:/Tomcat/work/Standalone/localhost/_/query_jsp.java:71: cannot resolve symbol
[javac] symbol : variable conn
[javac] location: class org.apache.jsp.query_jsp
[javac] conn.close();
[javac] ^
[javac] 4 errors