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 }