【发布时间】:2016-11-26 12:28:01
【问题描述】:
我们在学校有一个项目,我想使用 SQLite。
我在互联网上做了一个教程,它使用 NetBeans 将我连接到我的数据库上,它可以工作,但我的老师可能没有 NB,所以我尝试在 javac 上编译它。 所以当我测试它时会出现。
Connection.java:72: error: incompatible types: java.sql.Connection cannot be converted to Connection
conn = DriverManager.getConnection("jdbc:sqlite:test.db");
^
Connection.java:78: error: cannot find symbol
Statement stmt = conn.createStatement();
^
symbol: method createStatement()
location: variable conn of type Connection
2 errors
所以我的代码在这里
try {
Connection conn = null;
try {
Class.forName("org.sqlite.JDBC");
conn = DriverManager.getConnection("jdbc:sqlite:c:\sqlite\test.db");
} catch ( Exception e ) {
System.err.println( e.getClass().getName() + ": " + e.getMessage() );
System.exit(0);
}
System.out.println("Opened database successfully");
Statement stmt = conn.createStatement();
// create a new table
stmt.execute(sqldoc);
stmt.execute(sqlaud);
stmt.execute(sqlvid);
stmt.execute(sqlliv);
stmt.execute(sqlcli);
stmt.execute(sqlemp);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
在另一个文件中,我还有一个错误,涉及 getMetaData()
我没有在互联网上查看过这个,但我没有找到这个错误的答案
【问题讨论】:
-
导入错误,确保你已经正确导入java.sql.Connection
-
在 Java 文件的顶部使用
import java.sql.Connection。 -
和你的问题无关,但是Netbeans可以管理maven类型的项目,而且我觉得sun下的每个Java IDE都支持maven项目,所以你老师的IDE应该也支持吧。