forked from shushmita-das/SpaceJammer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabase.java
32 lines (26 loc) · 1.01 KB
/
Database.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
import java.sql.*;
public class Database {
public static void main( String args[] ) {
Connection c = null;
Statement stmt = null;
//Try and catch error exception handling
try {
//Getting connection
Class.forName("org.sqlite.JDBC");
c = DriverManager.getConnection("jdbc:sqlite:test.db");
System.out.println("Opened database successfully"); //Printing out database creation message
// Creating statement
stmt = c.createStatement();
// Createing a table Score
String sql = "CREATE TABLE SCORE " +
"(SCORE INT PRIMARY KEY NOT NULL)";
stmt.executeUpdate(sql);
stmt.close(); //Closing statement
c.close(); //Closing connection
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Table created successfully"); //Printing out table creation message
}
}