Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
|
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 26th, 2004, 11:54 AM
Authorized User
 
Join Date: Jul 2003
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default visit Access Database error

I use JSP to visit Access Database by using ODBC.I put code of visiting Access Database in JavaBean.
JavaBean code is follows:
/*sql.java*/
package common;
import java.sql.*;
public class sql {
  String sDBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
  String sConnStr="jdbc:odbc:JSP";
  Connection conn=null;
  Statement stmt;
  ResultSet rs=null;
  public sql() {
    try{
      Class.forName(sDBDriver);
    }
    catch(ClassNotFoundException e){
      System.err.println("open database error:"+e.getMessage());
    }
  }
  public ResultSet executeQuery(String sql){
    try{
      conn=DriverManager.getConnection(sConnStr);
      stmt=conn.createStatement();
      rs=stmt.executeQuery(sql); //33th line
    }
    catch(SQLException ex){
      ex.printStackTrace();
    }
    return rs;
  }
}

The I call this JavaBean from JSP,but I found a puzzling thing,when I first time call JavaBean,it can visited Access Database,but when I second time to call JavaBean,I found it can't visited Access Database,like follows:

<%jsp:userBean id="jsp" scope="session" class="common.sql"%>
...
String sql="insert into test(a1,a2) values ('a','b')";
ResultSet rs=jspEx.executeQuery(sql); //first time,it can visit Access Database
rs.close();
sql="select * from test";
rs=jspEx.executeQuery(sql); //second time,it can't visit Access Database

java.sql.SQLException: No ResultSet was produced
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcO dbcStatement.java:259)
at common.sql.executeQuery(sql.java:33)
at java.lang.Thread.run(Thread.java:536)

Why?
Any idea will be appreciated!
Edward



 
Old March 28th, 2004, 12:09 AM
Authorized User
 
Join Date: Feb 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to cash
Default

The problem is "rs.close(); ".You delete the connection of "rs".
So you could make another connection.







Similar Threads
Thread Thread Starter Forum Replies Last Post
why I can't visit Tomcat5.5.12 (Urgent) Edward King Apache Tomcat 2 November 30th, 2005 01:13 PM
Database connection error. asp.net/dreamw/access peacesquid Classic ASP Databases 1 July 28th, 2005 06:56 PM
Why Linux can't visit public net? Edward King Linux 1 September 7th, 2004 09:55 AM
Do you want to visit Imar's Homepage?Click here. nw61 C# 0 May 13th, 2004 04:30 AM
about visit c-api 6cet6 VS.NET 2002/2003 0 March 25th, 2004 06:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.