用J2EE开发的网站,可以应用到图书馆,图书超市

源代码在线查看: conn.java

软件大小: 3721 K
上传用户: zhuying0000
关键词: J2EE 网站 图书馆 图书
下载地址: 免注册下载 普通下载 VIP

相关代码

				package ksnb;
				
				import java.util.*;
				import java.sql.*;
				import java.net.*;
				
				public class conn {
				   Connection con=null;
				   public conn() throws connException{
				       String driver = null;
				       String user = null;
				       String pass = null;
				       String dbURL = null;
				       //生成Properties对象,用来获取配置文件(config)内容
				       java.util.Properties properties = null;
				       try {
				           properties = PropertiesManager.getProperties("config");
				           driver = properties.getProperty("jdbc.driver");
				           user = properties.getProperty("jdbc.user");
				           pass = properties.getProperty("jdbc.password");
				           dbURL = properties.getProperty("jdbc.dbURL");
				           //连接数据库
				           Class.forName(driver);
				           con= DriverManager.getConnection(dbURL, user, pass);
				           System.out.println("连接数据库成功!");
				       }
				       catch (java.io.FileNotFoundException e) {
				            throw new connException("JDBC Properties File Read Error!");
				        } catch (MissingResourceException e) {
				            throw new connException("JDBC Properties File Not Found!");
				        } catch (ClassNotFoundException e) {
				            throw new connException("No Driver Available!");
				        } catch (SQLException se) {
				            throw new connException(se.getMessage());
				        }
				   }
				
				    public Connection getConncetion() throws connException {
				        return con;
				    }
				    public void conClose(){
				        try{
				        con.close();
				        }catch(Exception e){}
				    }
				}
							

相关资源