-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnect.java
43 lines (39 loc) · 1.1 KB
/
Connect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package net.sqlitetutorial;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author sqlitetutorial.net
*/
public class Connect {
/**
* Connect to a sample database
*/
public static void connect() {
Connection conn = null;
try {
// db parameters
String url = "jdbc:sqlite:C:/sqlite/db/MOVIES.db";
// create a connection to the database
conn = DriverManager.getConnection(url);
System.out.println("Connection to SQLite has been established.");
} catch (SQLException e) {
System.out.println(e.getMessage());
} finally {
try {
if (conn != null) {
conn.close();
}
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
connect();
}
}