Advertisement
Guest User

Untitled

a guest
Jul 11th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. package cbt_Rechenwerk;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.sql.*;
  8. import java.util.ArrayList;
  9.  
  10. import javax.xml.parsers.ParserConfigurationException;
  11. import javax.xml.parsers.SAXParser;
  12. import javax.xml.parsers.SAXParserFactory;
  13.  
  14. import org.xml.sax.SAXException;
  15. import org.xml.sax.helpers.DefaultHandler;
  16.  
  17. public class DBConnection2
  18. {
  19. static Connection con;
  20.  
  21. static boolean is_connected=false;
  22.  
  23. String url;
  24. String username;
  25. String password;
  26.  
  27. ArrayList <DBProperty> v_dbProperties = new ArrayList<DBProperty>();
  28.  
  29.  
  30. public DBConnection2()
  31. {
  32.  
  33. try
  34. {
  35. SAXParserFactory factory = SAXParserFactory.newInstance();
  36. SAXParser saxParser = factory.newSAXParser();
  37. DefaultHandler handler = new Hndl_DBProperties_Deployer(v_dbProperties);
  38. saxParser.parse(new File("DeploymentDescriptor.xml"), handler );
  39. }
  40. catch (FileNotFoundException e)
  41. {
  42. System.err.println("Datei kann nicht gefunden werden");
  43. e.printStackTrace();
  44. }
  45. catch (ParserConfigurationException e)
  46. {
  47. System.err.println("Datei ist nicht wohlgeformt");
  48. e.printStackTrace();
  49. }
  50. catch (SAXException e)
  51. {
  52. System.err.println("Datei ist nicht wohlgeformt");
  53. e.printStackTrace();
  54. }
  55. catch (IOException e)
  56. {
  57.  
  58. }
  59.  
  60. while(!is_connected)
  61. {
  62. for (DBProperty db : v_dbProperties)
  63. {
  64. url = db.db_url;
  65. username = db.db_user;
  66. password = db.db_password;
  67.  
  68. try
  69. {
  70. Class.forName("oracle.jdbc.driver.OracleDriver");
  71. }
  72. catch (ClassNotFoundException e)
  73. {
  74. System.out.println(e.getMessage());
  75. }
  76. try
  77. {
  78. con = DriverManager.getConnection("jdbc:oracle:thin:@"+url,username,password);
  79. is_connected=true;
  80. }
  81. catch (SQLException e)
  82. {
  83. System.out.println(e.getMessage());
  84. }
  85. }
  86. }
  87.  
  88. }
  89.  
  90. public static Connection getInstance()
  91. {
  92. if(con == null)
  93. {
  94. new DBConnection2();
  95. }
  96. return con;
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement