位置:
首页
→
Java EE应用服务器
→
Tomcat
问题状态
java.sql.SQLException: Connection is closed.[Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]对象名 tb_rose无效
悬赏分:10
已经过期
过期时间2008-8-27 15:52
java.sql.SQLException:
Connection
is
closed.[Microsoft][SQLServer
2000
Driver
for
JDBC][SQLServer]对象名
'tb_rose'
无效
tb_rose是一个表名
●开发语言:
★★★ 问题补充 ★★★
(2008-8-27 15:53:12)
java.sql.SQLException:
Connection
is
closed.[Microsoft][SQLServer
2000
Driver
for
JDBC][SQLServer]对象名
'tb_rose'
无效
请问是什么原因?
★★★ 问题补充 ★★★
(2008-8-27 16:03:20)
这个是源代码:
import
javax.naming.*;
import
javax.sql.DataSource;
import
java.sql.*;
public
class
Condata{
private
static
Connection
con;
ResultSet
rs;
private
static
Context
ctx;
private
static
Context
env;
public
static
synchronized
Connection
getConnection()
throws
Exception{
try{
ctx=new
InitialContext();
env=(Context)ctx.lookup("java:comp/env");
DataSource
ds=(DataSource)env.lookup("jdbc/sa");
return
con=ds.getConnection();
}
catch(SQLException
e){
throw
e;
}
catch(NamingException
e){
throw
e;
}
}
public
ResultSet
executeQuery(String
sql){
try{
Statement
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs=stmt.executeQuery(sql);
}catch(SQLException
er){
System.err.print(er.getMessage());
}
return
rs;
}
public
int
executeUpdate(String
sql){
int
result=0;
try{
Statement
stmt=con.createStatement();
result=stmt.executeUpdate(sql);
}catch(SQLException
eer){
System.out.print(eer.getMessage());
}
return
result;
}
public
void
close(){
try{
if(con!=null){
con.close();
}
}catch(Exception
err){
System.out.print(err);
}
try{
if(rs!=null){
rs.close();
}
}catch(Exception
err){
System.out.print(err);
}
}
提问者:
luyougong@sohu.com - 头衔:初级程序员
回复答案
共2条
用户没有权限的原因
回答者:
crown_2008@126.com
-
头衔:开发爱好者
2008-8-31 20:06:48
可能是还没执行getConnection()
吧~
你调用下试试
回答者:
442895765@qq.com
-
头衔:开发爱好者
2008-8-30 6:01:30
我的回答:
回答即可得10分,被采纳则可得50分+悬赏分。
验证码
最新问题
欢迎使用本系统,智囊团。踊跃回答,赢得积分。
使用有问题请到
帮助
关于我们
|
商务合作
|
招聘信息
|
客服中心
|
服务条款
|
免责声明
|
网站导航
|
java培训
Copyright 2007 zhinangtuan.net.cn all rights reserved 版权所有