Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ConnDB.java~28~
Package: LibraryManage.rar [view]
Upload User: toby828
Upload Date: 2015-06-26
Package Size: 8558k
Code Size: 3k
Category:
Jsp/Servlet
Development Platform:
Java
- package com.core;
- import java.sql.*;
- public class ConnDB {
- public Connection conn=null;
- public ResultSet rs=null;
- public Statement stmt=null;
- private static String proxool = "org.logicalcobwebs.proxool.ProxoolDriver";
- private static String poolname = "proxool.library";
- public static Connection getConnection() {
- Connection conn = null;
- try {
- Class.forName(proxool);
- conn = DriverManager.getConnection(poolname);
- } catch (ClassNotFoundException e) {
- System.out.println(e.getMessage());
- } catch (SQLException e) {
- System.out.println(e.getMessage());
- }
- if (conn == null) {
- System.out.println("没有获取到数据库连接");
- }
- return conn;
- }
- /*
- *功能:执行查询语句
- */
- public ResultSet executeQuery(String sql) {
- try {
- conn = getConnection();
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- rs = stmt.executeQuery(sql);
- }
- catch (SQLException ex) {
- System.err.println(ex.getMessage());
- }
- return rs;
- }
- /*
- *功能:执行更新操作
- */
- public int executeUpdate(String sql) {
- int result = 0;
- try {
- conn = getConnection();
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- result = stmt.executeUpdate(sql);
- }
- catch (SQLException ex) {
- result = 0;
- }
- try {
- stmt.close();
- }
- catch (SQLException ex1) {
- }
- return result;
- }
- public int executeUpdate_id(String sql) {
- int result = 0;
- try {
- conn = getConnection();
- stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
- ResultSet.CONCUR_READ_ONLY);
- result = stmt.executeUpdate(sql);
- String ID = "select @@IDENTITY as id";
- rs = stmt.executeQuery(ID);
- if (rs.next()) {
- int autoID = rs.getInt("id");
- result = autoID;
- }
- }
- catch (SQLException ex) {
- result = 0;
- }
- return result;
- }
- /*
- *功能:关闭数据库的连接
- */
- public void close() {
- try {
- if (rs != null) {
- rs.close();
- }
- }
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
- try {
- if (stmt != null) {
- stmt.close();
- }
- }
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
- try {
- if (conn != null) {
- conn.close();
- }
- }
- catch (Exception e) {
- e.printStackTrace(System.err);
- }
- }
- }