1
我们在学校有一个项目,我想使用SQLite。编译错误不兼容的类型:java.sql.Connection不能转换为连接
我做这使用NetBeans我连我的DB和它的工作,但我的老师可能没有注意,所以我尝试编译它的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中的正确使用 – developer
进口'在java.sql.Connection'您的Java文件的顶部。 –
与你的问题没有关系,但Netbeans可以管理Maven类型的项目,我认为每个在阳光下的Java IDE都支持Maven项目,所以你的老师的IDE很可能也会支持它。 – fvu