游戏开发论坛

 找回密码
 立即注册
搜索
查看: 927|回复: 0

数据库连接池的JAVABEAN wxh zt

[复制链接]

1367

主题

1993

帖子

2118

积分

金牌会员

Rank: 6Rank: 6

积分
2118
发表于 2008-1-2 20:09:00 | 显示全部楼层 |阅读模式
package db;
import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;
public class dbbean{
Connection conn=null;
Statement stmt=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
Context initCtx=null;
Context envCtx=null;
DataSource ds=null;

public dbbean(){
  try
  {
         initCtx = new InitialContext();
         envCtx = (Context) initCtx.lookup("java:comp/env");
         ds = (DataSource) envCtx.lookup("jdbc/myoracle");
         conn = ds.getConnection();
         stmt = conn.createStatement();
         pstmt = conn.createStatement();
  }
  catch(Exception e)
  {
   e.printStackTrace();
  }
}
public ResultSet executeQuery(String sql){
  try
  {
   rs=stmt.executeQuery(sql);
  }
  catch(SQLException e)
  {
   e.printStackTrace();
  }
  return rs;
}
public int executeUpdate(String sql){
  try
  {
   int i=stmt.executeUpdate(sql);
   return i;
  }
  catch(SQLException e)
  {
   e.printStackTrace();
   return -1;
  }
}
public Connection getConn(){
  return conn;
}
public getPstmt(){
  return pstmt;
}
public PreparedStatement getPstmt(){
  return pstmt;
}
public close(){
  try
  {
   rs.close();
   stmt.close();
   conn.close();
  }
  catch(SQLException e)
  {
   e.printStackTrace();
  }
}
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2026-1-23 23:54

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表