Guest User

Untitled

a guest
Jun 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. package DB;
  7.  
  8. /**
  9. *
  10. * @author microcosm
  11. */
  12.  
  13.  
  14. import java.sql.Connection;
  15. import java.sql.DriverManager;
  16. /*
  17. * DatabBase.java
  18. *
  19. * Created on August 30, 2007, 5:19 PM
  20. *
  21. * To change this template, choose Tools | Template Manager
  22. * and open the template in the editor.
  23. */
  24.  
  25. /**
  26. *
  27. * @author ganesheway
  28. */
  29. public class DataSources {
  30.  
  31. static String username = "tms";
  32. static String password = "tms";
  33.  
  34. public static Connection getOracleConnection() {
  35. String driver = "oracle.jdbc.OracleDriver";
  36. String url = "jdbc:oracle:thin:@localhost:1521:XE";
  37.  
  38.  
  39. try {
  40.  
  41. Class.forName(driver); // load Oracle driver
  42. Connection conn = DriverManager.getConnection(url, username, password);
  43. return conn;
  44.  
  45. } catch (Exception ex) {
  46. ex.printStackTrace();
  47. } // load Oracle driver
  48. return null;
  49. }
  50.  
  51.  
  52.  
  53. public static void main(String args[])throws Exception{
  54. DataSources db = new DataSources();
  55. Connection con = db.getOracleConnection();
  56. if(con==null){
  57. System.out.println("connection not established");
  58. }
  59. else{
  60. System.out.println("connection established");
  61. }
  62. }
  63.  
  64. }
Add Comment
Please, Sign In to add comment