0

I am trying to create a table in sqlite3 using java and I created the following procedure. I get the following error.

Zoo.java:30: error: cannot find symbol
      Statement st = null;
      ^
  symbol:   class Statement
  location: class Zoo
1 error
 //creates the table
    public void creaTaulaCategories() throws SQLException {
        String sql = "CREATE TABLE CATEGORIES(" +
                         "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                         "nom VARCHAR(40))";
        Statement st = null;
        try{
                st = conn.createStatement();
                st.executeUpdate(sql);
        }finally{
                if (st != null) {
                        st.close();
                }
        }
    }
freez
  • 1

1 Answers1

0

Thanks! @khelwood

import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement; //Missing import ;(
public class Zoo{
    private static final String NOM_BASE_DE_DADES = "animals.bd";
    private static final String CADENA_DE_CONNEXIO = "jdbc:sqlite:" +
                                                     NOM_BASE_DE_DADES;
    private Connection conn = null;

    public void connecta() throws SQLException {
        if (conn != null) return;
        conn = DriverManager.getConnection(CADENA_DE_CONNEXIO);
    }

    public void desconnecta() throws SQLException {
        if (conn == null) return;
        conn.close();
    }
    //creates the table
    public void creaTaulaCategories() throws SQLException {
        String sql = "CREATE TABLE CATEGORIES(" +
                         "id INTEGER PRIMARY KEY AUTOINCREMENT," +
                         "nom VARCHAR(40))";
        Statement st = null;
        try{
                st = conn.createStatement();
                st.executeUpdate(sql);
        }finally{
                if (st != null) {
                        st.close();
                }
        }
    }
}
freez
  • 1