作业帮 > 综合 > 作业

variable con might not have been initialized

来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/04/27 04:14:12
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
英文提示的意思是变量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();
}
}
}