public class GestorBase{
public static void main(String[] args){
try
{
Class.forName("org.sqlite.JDBC");
}
catch (ClassNotFoundException e) {
System.out.println("Unable to load driver class");
// TODO: handle exception
}
try {
Connection con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite");
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("error al buscar la base de datos");
}
Statement sentencia = con.createStatement();
}}
eclipse 说:
"con" variable cannot be resolved to a type.
为什么?
最佳答案
con
变量是 try block 的局部变量,
try {
Connection con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite");
}
您正在 try block 之外访问 con
。
应该是
Connection con = null;
Statement sentencia = null;
try {
con = DriverManager.getConnection("jdbc:sqlite:db/Freepark.sqlite");
sentencia = con.createStatement();
} catch (SQLException e) {
// TODO Auto-generated catch block
System.out.println("error al buscar la base de datos");
} catch (Exception ex){
//handle it
}
关于java - 无法解析连接变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4348103/