variable con might not have been initialized什么错误啊?我已经初始化了啊,Connection con=null;con=DriverManager.getConnection("jdbc:odbc:sun","","");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 为什么它还是说没有呢
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/11 11:48:50
![variable con might not have been initialized什么错误啊?我已经初始化了啊,Connection con=null;con=DriverManager.getConnection(](/uploads/image/z/7761760-16-0.jpg?t=variable+con+might+not+have+been+initialized%E4%BB%80%E4%B9%88%E9%94%99%E8%AF%AF%E5%95%8A%3F%E6%88%91%E5%B7%B2%E7%BB%8F%E5%88%9D%E5%A7%8B%E5%8C%96%E4%BA%86%E5%95%8A%2CConnection+con%3Dnull%3Bcon%3DDriverManager.getConnection%28%22jdbc%3Aodbc%3Asun%22%2C%22%22%2C%22%22%29%3BClass.forName%28%22sun.jdbc.odbc.JdbcOdbcDriver%22%29%3B+%E4%B8%BA%E4%BB%80%E4%B9%88%E5%AE%83%E8%BF%98%E6%98%AF%E8%AF%B4%E6%B2%A1%E6%9C%89%E5%91%A2)
variable con might not have been initialized什么错误啊?我已经初始化了啊,Connection con=null;con=DriverManager.getConnection("jdbc:odbc:sun","","");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 为什么它还是说没有呢
variable con might not have been initialized
什么错误啊?
我已经初始化了啊,
Connection con=null;
con=DriverManager.getConnection("jdbc:odbc:sun","","");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
为什么它还是说没有呢
variable con might not have been initialized什么错误啊?我已经初始化了啊,Connection con=null;con=DriverManager.getConnection("jdbc:odbc:sun","","");Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 为什么它还是说没有呢
英文提示的意思是变量con没有被初始化,你应该在申明之后马上把它初始化吧.下面是一个jsp连接oracle数据库的代码,我以前做项目时照着一本书一个一个字母敲下来的,应该没有错误吧,
package firm;
import java.sql.*;
public class firm
{
String sDBDrive ="sun.jdbc.odbc.JdbcOdbcDrive";
String sConnStr="jdbc:odbc:firm";
private Connection conn=null;
private Statement stmt=null;
ResultSet rs=null;
public firm()
{
try
{
Class.forName(sDBDrive);
}
catch (java.lang.ClassNotFoundException e)
{
System.err.println("virtual_1():"+e.getMessage());
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
Connection conn=DriverManager.getConnection("jdbc:odbc:firm","echo1004","echo1004shma");
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
public void executeUpdate(String sql)
{
stmt=null;
rs=null;
try
{
Connection conn=DriverManager.getConnection("jdbc:odbc:firm","echo1004","echo1004shma");
stmt=conn.createStatement();
stmt.executeQuery(sql);
stmt.close();
conn.close();
}
catch (SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
}
public void closeStmt()
{
try
{
stmt.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
public void closeConn()
{
try
{
conn.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
变量没有初始化
java我不懂