我正在尝试将 SQLite 驱动程序添加sqlitejdbc-v056.jar
到我的 netbeans 7.1.2 项目中,我已经创建了数据库和所有内容,但没有任何问题,但是当我尝试使用以下代码(我上网)连接到数据库时,它不起作用
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();
stat.executeQuery
给出以下错误给我一个问题
cannot find symbol
symbol: method executeQuery(java.lang.String)
location: variable stat of type java.beans.Statement
有谁知道为什么会这样?
编辑:进口
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
当我添加import java.sql.Statement;
它给它一个错误并说要删除未使用的导入