搞了一个星期了,真的急死我了,请各位大哥大姐帮帮忙!看看我的关于查询数据库的问题!一定加分

java_prince 2001-11-07 07:08:10
我编了个通过JDBC-ODBC桥连接ACCESS的查询运行时JSWDK11报出如下问题,其中带码如下:(数据库和数据源都建立设置好了,其中能运行其他JSP程序)
(1)连接数据库的BEAN如下:
import java.io.*;
import java.sql.*;

public class DBconn{
String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr="jdbc:odbc:customers";
Connection conn=null;
ResultSet rs=null;
public DBconn ()
{
try{
Class.forName(DBDriver);
}catch (java.lang.ClassNotFoundException e){
System.err.println("DBconn():"+e.getMessage());}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try{
conn=DriverManager.getConnection(ConnStr);
Statement stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}catch(SQLException ex){System.err.println("aq.executeQuery:"+ex.getMessage());}

return rs;
}
}
编译已经成功!

(2)利用上面的BEAN的查询的JSP程序如下:
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html;charset=gb2312">
<TITLE> kehudiaocha</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<% @ page language="java" ,import="java.sql.*"%>
<jsp: useBean id="DBconn1" scope="page" class="DBconn"/>
<% ResultSet RS=DBconn1.executeQuery("select * from customers");
while(RS.next()){
out.print(RS.getString("name"));
out.print(RS.getString("address"));
out.print(RS.getString("info"));
}
RS.close();
%>
</BODY>
</HTML>

运行报错如下:
JSWDK WebServer Version 1.0.1
Loaded configuration from: file:D:\JSWDK11\webserver.xml
endpoint created: localhost/127.0.0.1:8080
com.sun.jsp.runtime.JspServlet: init
Scratch dir for the JSP engine is: work\%3A8080%2F
IMPORTANT: Do not modify the generated servlets
com.sun.web.core.DefaultServlet: init
HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
java.io.IOException: Socket Closed
at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:421)
at java.net.Socket$1.run(Socket.java:335)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.Socket.getInputStream(Socket.java:332)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)
Unhandled error! You might want to consider having an error page to report such
errors more gracefully
com.sun.jsp.JspException: Compilation failed:work\%3A8080%2F\customers_jsp_1.jav
a:69: 输入字符无效。
@ page language="java" ,import="java.sql.*"
^
work\%3A8080%2F\customers_jsp_1.java:69: 项丢失。
@ page language="java" ,import="java.sql.*"
^
work\%3A8080%2F\customers_jsp_1.java:69: 需要 ';'。
@ page language="java" ,import="java.sql.*"
^
3 个错误

at com.sun.jsp.compiler.Main.compile(Main.java:347)
at com.sun.jsp.runtime.JspLoader.loadJSP(JspLoader.java:135)
at com.sun.jsp.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspS
ervlet.java:77)
at com.sun.jsp.runtime.JspServlet$JspServletWrapper.service(JspServlet.j
ava:87)
at com.sun.jsp.runtime.JspServlet.serviceJspFile(JspServlet.java:218)
at com.sun.jsp.runtime.JspServlet.service(JspServlet.java:294)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
)
at com.sun.web.core.Context.handleRequest(Context.java:414)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)
HANDLER THREAD PROBLEM: java.io.IOException: Socket Closed
java.io.IOException: Socket Closed
at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:421)
at java.net.Socket$1.run(Socket.java:335)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.Socket.getInputStream(Socket.java:332)
at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)

...全文
151 点赞 收藏 7
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yun15291li 2001-11-11
都告诉你了。后面多了一个逗号。还不改。
回复
ls 2001-11-08
改:<%@ page language="java", import="java.sql.*"%>
为:<%@ page language="java" import="java.sql.*"%>
或:<%@ page language="java"%>
<%@ page import="java.sql.*"%>
回复
idohim 2001-11-08
我试了
可是它说我:
500 Servlet Exception
/test/dbjsp.jsp:7: expected `%>' at `,' (for <%@ at line 7)


--------------------------------------------------------------------------------
Resin 2.0.0 (built Fri Jun 8 12:04:24 PDT 2001)


第七行:<%@ page language="java", import="java.sql.*"%>
回复
yun15291li 2001-11-07
to(木心)哦。对。这一点我还没看到。呵呵。不要给他加分。我看到了也会告诉你的。
回复
muxinpp 2001-11-07
@和<%分开了!
回复
yun15291li 2001-11-07
jsp程序里language="java"后面没有逗号。一个错误解决娄。
package test;
import java.sql.*;
import java.lang.String;

public class dd {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:dd";
Connection conn = null;
ResultSet rs = null;

public dd() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("dd(): " + e.getMessage());
}
}

public ResultSet executeQuery(String sql) {
rs = null;
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
return rs;
}

public void update(String sql){
try {
conn = DriverManager.getConnection(sConnStr);
Statement stmt = conn.createStatement();
stmt.executeUpdate(sql);
}
catch(SQLException ex) {
System.err.println("aq.executeQuery: " + ex.getMessage());
}
}
}
用这个bean吧。再把响应部分改一下就可以了。也就是数据源部分。这个bean是经过测试正确的。
加分吧。呵呵^_^
回复
java_prince 2001-11-07
哦,我用的是WINDOW2000 SERVER 和JDK1.3和JSWDK
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2001-11-07 07:08
社区公告
暂无公告