0

I'm trying to learn how to make an SQLite database with this tutorial http://www.sqlitetutorial.net/sqlite-java/create-table/ but I'm stuck.

I wrote the code like they said (changing just the name of the class and the path to find the file) using NetBeans.

package createnewtable;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreateNewTable {

    public static void createNewTable(){
        //SQLite connection string
        String url = "jdbc:sqlite:/Volumes/..../Esercizi/test.db";
        //SQL statement for creating a new table
        String sql = "CREATE A TABLE IF NOT EXISTS warehouses ("
            + "id integer PRIMARY KEY,"
            + "name text NOT NULL,"
            + "capacity real)";

        try (Connection conn = DriverManager.getConnection(url);
            Statement stmt = conn.createStatement()){
            //Create a new Table
            stmt.execute(sql);
        } catch(SQLException e){
             System.out.println(e.getMessage());
        }
    }

     public static void main(String[] args) {          
        createNewTable();
    }  
}

But when I run the code the output is the following:

No suitable driver found for jdbc:sqlite:/Volumes/.../Esercizi/test.db"

Can you help me? Where is my mistake?

Thanks in advance

Ingialldus
  • 287
  • 1
  • 4
  • 7

1 Answers1

0

Do you have the JAR library in your classpath?

https://bitbucket.org/xerial/sqlite-jdbc

Mariano L
  • 1,809
  • 4
  • 29
  • 51
  • Ehm... I forgot to add the JAR file in the library and after that the new problem was about the ("A").. so I change the code `CREATE A TABLE` in `CREATE TABLE` and it works! Yeah! Thank you very much! – Ingialldus Feb 20 '17 at 21:27