I am trying to add SQLite driver sqlitejdbc-v056.jar into my netbeans 7.1.2 project, I have created the database and everything without any problem but when I try to connect to the database with the below code (which I got online) it is not working
public static void main(String args[]) throws Exception {
Class.forName("org.sqlite.JDBC");
Connection conn = DriverManager.getConnection("jdbc:sqlite:Vinit");
Statement stat = (Statement) conn.createStatement();
stat.executeUpdate("drop table if exists school;");
stat.executeUpdate("create table school (name, state);");
PreparedStatement prep = conn.prepareStatement(
"insert into school values (?, ?);");
prep.setString(1, "UTD");
prep.setString(2, "texas");
prep.addBatch();
prep.setString(1, "USC");
prep.setString(2, "california");
prep.addBatch();
prep.setString(1, "MIT");
prep.setString(2, "massachusetts");
prep.addBatch();
conn.setAutoCommit(false);
prep.executeBatch();
conn.setAutoCommit(true);
ResultSet rs = stat.executeQuery("select * from school;");
while (rs.next()) {
System.out.print("Name of School = " + rs.getString("name") + " ");
System.out.println("state = " + rs.getString("state"));
}
rs.close();
conn.close();
It is giving me a problem with stat.executeQuery giving the following error
cannot find symbol
symbol: method executeQuery(java.lang.String)
location: variable stat of type java.beans.Statement
Does anyone know why this is happening?
EDIT: Imports
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
When I add import java.sql.Statement; it gives it an error and says to remove unused import
check whether
Statementinterface is of correct package ie.java.sql.Statement;in your code
import java.beans.Statement;its incorrect change it toimport java.sql.Statement;