Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package oracle;
- import java.sql.*;
- import java.util.*;
- /**
- *
- * @author marti
- */
- public class Conexion {
- private static String JDBC_DRIVER;
- private static String JDBC_URL;
- private static String JDBC_USER;
- private static String JDBC_PASS;
- private static Driver driver= null;
- private static String JDBC_FILE_NAME="oracle/jdbc";
- public static Properties loadProperties(String file){
- Properties prop=new Properties();
- ResourceBundle bundle=ResourceBundle.getBundle(file);
- Enumeration e=bundle.getKeys();
- String key=null;
- while(e.hasMoreElements()){
- key=(String)e.nextElement();
- prop.put(key, bundle.getObject(key));
- }
- JDBC_DRIVER=prop.getProperty("driver");
- JDBC_URL=prop.getProperty("url");
- JDBC_USER=prop.getProperty("user");
- JDBC_PASS=prop.getProperty("pass");
- return prop;
- }
- public static synchronized Connection getConnection() throws SQLException{
- if (driver==null){
- try{
- loadProperties(JDBC_FILE_NAME);
- Class jdbcDriver=Class.forName(JDBC_DRIVER);
- driver=(Driver)jdbcDriver.newInstance();
- DriverManager.registerDriver(driver);
- }catch(Exception e){System.out.println("Hubo un error en la carga de datos"); e.printStackTrace();}
- }
- return DriverManager.getConnection(JDBC_URL,JDBC_USER,JDBC_PASS);
- }
- }
Add Comment
Please, Sign In to add comment