aq.executeQuery: [Microsoft][ODBC Microsoft Access 驱动程序] 客户端的工作过多

davidnim 2003-06-25 10:19:09
请问如何解决?
JAVA文件代码如下:
package test;
import java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + 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;
}
}

...全文
372 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
unsalted 2003-06-30
  • 打赏
  • 举报
回复
这是我用的,每次查询后调用一下connectClose(),绝对不会再出现你说的情况。

package test;

/**
* Title: select insert update and delete
* Description: select insert update and delete
* Copyright: Copyright (c) 2003
* @author
* @version 1.0
*/

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.sql.Statement;
public class connectBean {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:db1";
Connection connect = null;
ResultSet rs = null;
Statement stmt = null;
public connectBean() {
try {
Class.forName(sDBDriver);
}
catch (java.lang.ClassNotFoundException e) {
System.err.println(e.getMessage());
}
}

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

public void executeUpdate(String sql) {
rs = null;
try {
connect = DriverManager.getConnection(sConnStr);
Statement stmt = connect.createStatement();
stmt.executeQuery(sql);
connect.close() ;
stmt.close();
}
catch (SQLException ex) {
System.err.println(ex.getMessage());
}

}
public void connectClose(){
if(connect !=null ){
try{
connect.close();
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
}
if(stmt != null){
try{
stmt.close();
}catch(SQLException ex){
System.err.println(ex.getMessage());
}
}
}
}
davidnim 2003-06-30
  • 打赏
  • 举报
回复
大家帮帮忙,这问题解决不了,无法向老板交代!
谢谢!
davidnim 2003-06-30
  • 打赏
  • 举报
回复
问题比较奇怪,先多谢大家。
估计是我的代码什么地方有问题,先把帐结了。我自己再慢慢跟。
davidnim 2003-06-29
  • 打赏
  • 举报
回复
加过类似的close方法如下,还是没有解决问题。
public void closeConn(){
try{
stmt.close();
conn.close();
}
catch(SQLException e){
e.printStackTrace();
}
}
www203 2003-06-29
  • 打赏
  • 举报
回复
package test;
import java.sql.*;
public class faq {
String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sConnStr = "jdbc:odbc:faq";
Connection conn = null;
ResultSet rs = null;
public faq() {
try {
Class.forName(sDBDriver);
}
catch(java.lang.ClassNotFoundException e) {
System.err.println("faq(): " + 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 close(){
conn.close();
}
}


你在每次外面取完数据的时候都调用一下该方法
wlei0411 2003-06-29
  • 打赏
  • 举报
回复
看看http://expert.csdn.net/Expert/topic/1404/1404957.xml?temp=9.421939E-02吧,
也许会有帮助!
davidnim 2003-06-29
  • 打赏
  • 举报
回复
access、ODBC最大连接数在那里设呢?
zxl19790710 2003-06-28
  • 打赏
  • 举报
回复
stmt.close();
conn.close()
kingdomzhf 2003-06-28
  • 打赏
  • 举报
回复
up
testjava 2003-06-28
  • 打赏
  • 举报
回复
package beans;

import java.io.PrintStream;
import java.sql.*;
import java.util.ResourceBundle;
import java.lang.*;

public class sql_data
{

ResourceBundle bundle=ResourceBundle.getBundle("db_config");

String sDBDriver=bundle.getString("sDBDriver");
String sConnStr=bundle.getString("sConnStr");
String username=bundle.getString("username");
String password=bundle.getString("password");

Connection conn;
Statement stmt;
ResultSet rs;

public sql_data()
{

conn = null;
stmt = null;
rs = null;
try
{
Class.forName(sDBDriver);
}
catch(ClassNotFoundException classnotfoundexception)
{
System.err.println("sql_data(): " + classnotfoundexception.getMessage());
}
}

public void executeInsert(String s)
{
try
{
conn = DriverManager.getConnection(sConnStr,username,password);
stmt = conn.createStatement(1004, 1007);
stmt.executeUpdate(s);
stmt.close();
conn.close();
}
catch(SQLException sqlexception)
{
System.err.println("sql_data.executeUpdate:" + sqlexception.getMessage());
}
}

public ResultSet executeQuery(String s)
{
rs = null;
try
{
conn = DriverManager.getConnection(sConnStr,username,password);
Statement statement = conn.createStatement(1004, 1007);
rs = statement.executeQuery(s);
}
catch(SQLException sqlexception)
{
System.err.println("aq.executeQuery: " + sqlexception.getMessage());
System.err.println("aq.executeQuerystrSQL: " + s);
}
return rs;
}

public void executeUpdate(String s)
{
try
{
conn = DriverManager.getConnection(sConnStr,username,password);
Statement statement = conn.createStatement(1004, 1007);
statement.executeUpdate(s);
}
catch(SQLException sqlexception)
{
System.err.println("aq.executeUpdate: " + sqlexception.getMessage());
System.err.println("aq.executeUpadatestrSQL: " + s);
}
}

public void executeDelete(String s)
{
try
{
conn = DriverManager.getConnection(sConnStr,username,password);
stmt = conn.createStatement(1004, 1007);
stmt.executeUpdate(s);
stmt.close();
conn.close();
}
catch(SQLException sqlexception)
{
System.err.println("sql_data.executeDelete:" + sqlexception.getMessage());
}
}

public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}
}

public void closeConn()
{
try
{
conn.close();
}
catch(SQLException sqlexception)
{
sqlexception.printStackTrace();
}
}
}
pantech_36 2003-06-28
  • 打赏
  • 举报
回复
应该是关闭链接的问题,不说access就是oracle都会有问题.
不过也跟你设的最大连`接数有关
Rangiggs 2003-06-28
  • 打赏
  • 举报
回复
去找一些连接池的方面的资料吧!
javalei 2003-06-28
  • 打赏
  • 举报
回复
这也许不是一个好方法,但是可以试试:
如果你用的是access
那换成mysql
davidnim 2003-06-28
  • 打赏
  • 举报
回复
stmt.close();
conn.close()
加上还是一样,问题没有解决。
davidnim 2003-06-27
  • 打赏
  • 举报
回复
我加上了conn.close()之后,测试打开大约30个页面,问题还是出现。
怎么办?
Ortega111 2003-06-26
  • 打赏
  • 举报
回复
最好把class.dorname();和DriverManager.getConnection()放在一个方法里(如构造函数),createStatement()在使用的时候在创建。
davidnim 2003-06-26
  • 打赏
  • 举报
回复
有没有人能帮我?
lovelanzhi716 2003-06-26
  • 打赏
  • 举报
回复
是不是你的连接没有关闭啊,你这样每执行一次都打开一个连接
系统资源都耗光了
你在程序里加个关闭试试
conn.close();

81,090

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧