DBConnection.java
资源名称:shihua.rar [点击查看]
上传用户:zghglow
上传日期:2022-08-09
资源大小:27227k
文件大小:1k
源码类别:
WEB源码(ASP,PHP,...)
开发平台:
JavaScript
- package com.chinacannel.common;
- import java.sql.*;
- public class DBConnection {
- protected boolean pooled = false;
- protected java.sql.Connection con;//for not pooled.
- public java.sql.Connection getConnection() {
- if(this.pooled) {
- /**@todo*/
- return null;
- } else {
- return this.con;
- }
- }
- public void freeConnection(java.sql.Connection con) {
- if(this.pooled) {
- try {
- con.close();
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- }
- }
- protected DBConnection() {
- if (this.pooled) {
- /**@todo*/
- }
- else {
- try {
- Class.forName("net.sourceforge.jtds.jdbc.Driver");
- this.con = java.sql.DriverManager.getConnection(
- "jdbc:jtds:sqlserver://localhost/bjywc",
- "sa", "sa");
- }
- catch (SQLException ex) {
- ex.printStackTrace();
- }
- catch (ClassNotFoundException ex) {
- ex.printStackTrace();
- }
- }
- }
- static public DBConnection instance = null;
- static public DBConnection getInstance() {
- if (instance == null) {
- instance = new DBConnection();
- }
- return instance;
- }
- }