Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private final static String DB_DRIVER = "org.h2.Driver";
- private final static String DB_URL = "jdbc:h2:~/test";
- private final static String DB_USERNAME ="sa";
- private final static String DB_PASSWORD = "";
- public Connection getConnection(){
- Connection connection = null;
- try {
- Class.forName(DB_DRIVER);
- connection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASSWORD);
- System.out.println("Connection OK");
- }catch(SQLException e){
- e.printStackTrace();
- System.out.println("Connection ERROR");
- }
- catch (ClassNotFoundException e){
- e.printStackTrace();
- System.out.println("Connection ERROR");
- }
- return connection;
- }
- public static void main(String[] args) {
- Util util = new Util();
- util.getConnection();
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <groupId>com.jdbc.tutorial</groupId>
- <artifactId>jdbc-tutorial</artifactId>
- <version>1.0-SNAPSHOT</version>
- <dependencies>
- <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.4.196</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement