码迷,mamicode.com
首页 > 数据库 > 详细

用单例连接oracle数据库

时间:2015-12-14 18:22:25      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

 1 package dao;
 2 
 3 import java.sql.Connection;
 4 import java.sql.DriverManager;
 5 import java.sql.SQLException;
 6 
 7 public class DbUser {
 8     private String driver="oracle.jdbc.driver.OracleDriver";
 9     private String user="scott";
10     private String url="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
11     private String password="ztoracle";
12     private static DbUser dbuser;
13     private Connection conn;
14     private DbUser(){
15         try {
16             Class.forName(driver);
17         } catch (ClassNotFoundException e) {
18             // TODO Auto-generated catch block
19             e.printStackTrace();
20         }
21     }
22     public static DbUser getDbUser(){
23         if(dbuser==null){
24             DbUser dbuser=new DbUser();
25         }
26         return dbuser;
27     }
28     public Connection getconnection(){
29         
30             try {
31                 conn=DriverManager.getConnection(url, user, password);
32             } catch (SQLException e) {
33                 // TODO Auto-generated catch block
34                 e.printStackTrace();
35             }
36         
37         return conn;
38         
39     }
40 }

 

用单例连接oracle数据库

标签:

原文地址:http://www.cnblogs.com/ztyy04126/p/5045595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!