Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void createTable(){
- //connect to database
- String url = percorsoDatabase;
- //Statement create new table
- String sql = "CREATE TABLE IF NOT EXISTS Tabella (id PRIMARY KEY," +
- "video TEXT," +
- "game TEXT," +
- "firstAction TEXT," +
- "secondAction TEXT," +
- "thirdAction TEXT);";
- try {
- Connection conn = DriverManager.getConnection(url);
- Statement stmt = conn.createStatement();
- stmt.execute(sql);
- } catch (SQLException e ){
- System.out.println(e.getMessage());
- }
- }
- public static void main(String[] args) {
- createNewDatabase();
- connection();
- createTable();
- }
- public static void createNewDatabase(){
- String url = percorsoDatabase;
- Connection conn;
- try {
- conn = DriverManager.getConnection(url);
- if (conn != null){
- DatabaseMetaData meta = conn.getMetaData();
- System.out.println("The driver name is" + meta.getDriverName());
- System.out.println("A new database has been created.");
- }
- } catch (SQLException e){
- System.out.println(e.getMessage());
- }
- }
- public static void connection(){
- Connection conn = null;
- try {
- //String url = "jdbc:sqlite://Volumes/Isma/Documenti/SUPSI/APA/Stage/"
- // + "Beans/esperimento/dati.db";
- conn = DriverManager.getConnection(percorsoDatabase);
- System.out.println("Connection to SQLite established.");
- } catch (SQLException e){
- System.out.println(e.getMessage());
- } finally {
- try {
- if (conn != null){
- conn.close();
- }
- } catch (SQLException e){
- System.out.println(e.getMessage());
- }
- }
- }
- url - a database url of the form jdbc:subprotocol:subname
Add Comment
Please, Sign In to add comment