Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cbt_Rechenwerk;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.sql.*;
- import java.util.ArrayList;
- import javax.xml.parsers.ParserConfigurationException;
- import javax.xml.parsers.SAXParser;
- import javax.xml.parsers.SAXParserFactory;
- import org.xml.sax.SAXException;
- import org.xml.sax.helpers.DefaultHandler;
- public class DBConnection2
- {
- static Connection con;
- static boolean is_connected=false;
- String url;
- String username;
- String password;
- ArrayList <DBProperty> v_dbProperties = new ArrayList<DBProperty>();
- public DBConnection2()
- {
- try
- {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- SAXParser saxParser = factory.newSAXParser();
- DefaultHandler handler = new Hndl_DBProperties_Deployer(v_dbProperties);
- saxParser.parse(new File("DeploymentDescriptor.xml"), handler );
- }
- catch (FileNotFoundException e)
- {
- System.err.println("Datei kann nicht gefunden werden");
- e.printStackTrace();
- }
- catch (ParserConfigurationException e)
- {
- System.err.println("Datei ist nicht wohlgeformt");
- e.printStackTrace();
- }
- catch (SAXException e)
- {
- System.err.println("Datei ist nicht wohlgeformt");
- e.printStackTrace();
- }
- catch (IOException e)
- {
- }
- while(!is_connected)
- {
- for (DBProperty db : v_dbProperties)
- {
- url = db.db_url;
- username = db.db_user;
- password = db.db_password;
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- }
- catch (ClassNotFoundException e)
- {
- System.out.println(e.getMessage());
- }
- try
- {
- con = DriverManager.getConnection("jdbc:oracle:thin:@"+url,username,password);
- is_connected=true;
- }
- catch (SQLException e)
- {
- System.out.println(e.getMessage());
- }
- }
- }
- }
- public static Connection getInstance()
- {
- if(con == null)
- {
- new DBConnection2();
- }
- return con;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement