当前位置: 技术问答>java相关
搞了一个星期了,真的急死我了,请各位大哥大姐帮帮忙!看看我的关于查询数据库的问题!一定加分
来源: 互联网 发布时间:2015-02-19
本文导语: 我编了个通过JDBC-ODBC桥连接ACCESS的查询运行时JSWDK11报出如下问题,其中带码如下:(数据库和数据源都建立设置好了,其中能运行其他JSP程序) (1)连接数据库的BEAN如下: import java.io.*; import java.sql.*; public class DBconn{ String ...
我编了个通过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程序如下:
kehudiaocha
运行报错如下:
JSWDK WebServer Version 1.0.1
Loaded configuration from: file:D:JSWDK11webserver.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%2Fcustomers_jsp_1.jav
a:69: 输入字符无效。
@ page language="java" ,import="java.sql.*"
^
work%3A8080%2Fcustomers_jsp_1.java:69: 项丢失。
@ page language="java" ,import="java.sql.*"
^
work%3A8080%2Fcustomers_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)
(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程序如下:
kehudiaocha
运行报错如下:
JSWDK WebServer Version 1.0.1
Loaded configuration from: file:D:JSWDK11webserver.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%2Fcustomers_jsp_1.jav
a:69: 输入字符无效。
@ page language="java" ,import="java.sql.*"
^
work%3A8080%2Fcustomers_jsp_1.java:69: 项丢失。
@ page language="java" ,import="java.sql.*"
^
work%3A8080%2Fcustomers_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)
|
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是经过测试正确的。
加分吧。呵呵^_^
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是经过测试正确的。
加分吧。呵呵^_^
|
改:
为:
或:
为:
或: