Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. private final static String DB_DRIVER = "org.h2.Driver";
  2. private final static String DB_URL = "jdbc:h2:~/test";
  3. private final static String DB_USERNAME ="sa";
  4. private final static String DB_PASSWORD = "";
  5.  
  6. public Connection getConnection(){
  7. Connection connection = null;
  8. try {
  9. Class.forName(DB_DRIVER);
  10. connection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
  11. System.out.println("Connection OK");
  12. }catch(SQLException e){
  13. e.printStackTrace();
  14. System.out.println("Connection ERROR");
  15. }
  16. catch (ClassNotFoundException e){
  17. e.printStackTrace();
  18. System.out.println("Connection ERROR");
  19. }
  20. return connection;
  21. }
  22.  
  23. public static void main(String[] args) {
  24. Util util = new Util();
  25. util.getConnection();
  26. }
  27.  
  28. <?xml version="1.0" encoding="UTF-8"?>
  29.  
  30. <groupId>com.jdbc.tutorial</groupId>
  31. <artifactId>jdbc-tutorial</artifactId>
  32. <version>1.0-SNAPSHOT</version>
  33.  
  34. <dependencies>
  35. <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
  36. <dependency>
  37. <groupId>com.h2database</groupId>
  38. <artifactId>h2</artifactId>
  39. <version>1.4.196</version>
  40. <scope>test</scope>
  41. </dependency>
  42. </dependencies>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement