社区
MS-SQL Server
帖子详情
請教一個Java.sql.SQLException錯誤問題
TyroneChen
2003-05-06 02:01:35
我在Java裡用連接池的方式來訪問數據庫,共有50條連接在連接池中,為什麼在真正多用戶使用時經常會出現:連接正忙碌於別一個hstml結果?
...全文
107
3
打赏
收藏
請教一個Java.sql.SQLException錯誤問題
我在Java裡用連接池的方式來訪問數據庫,共有50條連接在連接池中,為什麼在真正多用戶使用時經常會出現:連接正忙碌於別一個hstml結果?
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
3 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
TyroneChen
2003-05-06
打赏
举报
回复
隨便幫我看看有什麼地方得改進的沒有
TyroneChen
2003-05-06
打赏
举报
回复
以下是我在用的連接池代碼,一起研究研究:
package mrp.util;
import java.util.Stack;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.DriverManager;
import java.util.Enumeration;
public final class ConnectionPool {
public Stack pool;
private long timeout;
private static ConnectionPool mySelf;
private Connection con;
private ConnectionPool() {
}
public synchronized static ConnectionPool getInstance(){
if(mySelf == null){
mySelf = new ConnectionPool();
}
return mySelf;
}
public synchronized void initialize(int numCons,long timeout) throws SQLException{
if(pool != null){
throw new SQLException ("Pool already initialized");
}
try{
this.timeout = timeout;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
pool = new Stack();
for(int i=0 ; i < numCons;i++){
pool.push(DriverManager.getConnection("jdbc:odbc:MyDB","sa","123456"));
}
}
catch(ClassNotFoundException ex){
throw new SQLException("Driver not found!!!");
}
}
public synchronized Connection getConnection() throws SQLException{
if(pool == null){
throw new SQLException ("Pool not initialized,不能連接到數據庫,請重新登錄");
}
/*
while(pool.empty()){
try{
wait(timeout);
}
catch(InterruptedException ex){
throw new SQLException ("Connection not available,目前無有效的數據庫連接,請待會再試");
}
}
*/
con = (Connection) pool.pop();
return con;
}
public synchronized void releaseConnection(Connection con) throws SQLException {
if(pool == null){
throw new SQLException ("Pool not initialized,不能連接到數據庫,請重新登錄");
}
pool.push(con);
notifyAll();
}
public synchronized int getConnectionCount() throws Exception{
//返回當前連接池中可用的連接數
return pool.size();
}
public void destroyPool() throws SQLException {
if(pool == null){
throw new SQLException("Pool not initialized,不能連接到數據庫,請重新登錄");
}
while(!pool.empty()){
((Connection)pool.pop()).close();
pool = null;
}
}
}
enhydraboy
2003-05-06
打赏
举报
回复
你的DBManager有没有做过连接回收的清理工作?
还有,把你的连接池的java代码贴出来。
java
sql
next_关于错误:
java
.
sql
.
SQL
Exception
: 未调用 ResultSet.next的问题
1.` public Res evaluateCourse(@FormParam("stuId") int stuId, @FormParam("score") String score) {Res res = new Res();Connection con = null;ResultSet rs = null;String[] temp = score.split(",");i...
java
.
sql
.
SQL
Exception
:Unknown column '****' in 'where clause'错误问题原因以及如何解决?
在做数据库查询的时候,很容易碰到这样的错误。错误的原因是因为查询语句使用错误。比如一个用户表的属性有账号id(varchar)和密码password(varchar)当要查询的账号是数字的时候,如123456789可以使用查询语句select * from 表名 where id=123456789 但是,当要查询账号是字符串123456789@qq.com的时候,会报错
java
.
sql
.
SQL
E...
java
.
sql
.
SQL
Exception
:Unknown column 'admin' in 'where clause'错误问题
java
.
sql
.
SQL
Exception
:Unknown column 'admin' in 'where clause'
错误是由下面这句代码引起的:
ps=ct.prepareStatement("select passwd from users where username="+u+"'order by userId limit 0,1");
应该将其改为下面的形式:
ps=ct.prepar
java
.
sql
.
SQL
Exception
异常的解决方案
java
.
sql
.
SQL
Exception
是
Java
在数据库操作中经常遇到的一个异常。当使用JDBC(
Java
Database Connectivity)API与数据库进行交互时,如果发生错误,比如连接失败、
SQL
语句执行错误、数据访问问题等,就会抛出这个异常。
java
.
sql
.
SQL
Exception
: Parameter index out of range
springmvc+mybatis 整合时出现
java
.
sql
.
SQL
Exception
: Parameter index out of range(2>number of paramrters,which 1). 这里写代码片 insert into orders_no (ord_id,val) values (#{ord_id},1) on duplicate...
MS-SQL Server
34,876
社区成员
254,635
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章