当前位置: 技术问答>java相关
我的第一个bean,有错误,大家帮我看看。(在线)
来源: 互联网 发布时间:2017-04-09
本文导语: //以下是bean package qin; /** * Title: * Description: * Copyright: Copyright (c) 2002 * Company: * @author unascribed * @version 1.0 */ import java.sql.*; public class DBConnQ { private static String DBDriver="com.sybase.jdbc2.jdbc.SybD...
//以下是bean
package qin;
/**
*
*
*
*
* @author unascribed
* @version 1.0
*/
import java.sql.*;
public class DBConnQ {
private static String DBDriver="com.sybase.jdbc2.jdbc.SybDriver";
private static String url="jdbc:sybase:Tds:tiger:5000/hbxs";
private static String user="sa";
private static String pwd="";
public static Connection CreateConn()
{
try
{
Class.forName(DBDriver);
Connection conn=DriverManager.getConnection(url,user,pwd);
return conn;
}
catch(Exception e)
{
System.out.println(e.toString());
}
return null;
}
}
//以下是
Jsp1
JBuilder Generated JSP
调试就错误?什么原因?去掉
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from hb_cig_code");
rs.close();
stmt.close();
con.close();
就可以通过?难道这个地方错了吗?
package qin;
/**
*
Title:
*
Description:
*
Copyright: Copyright (c) 2002
*
Company:
* @author unascribed
* @version 1.0
*/
import java.sql.*;
public class DBConnQ {
private static String DBDriver="com.sybase.jdbc2.jdbc.SybDriver";
private static String url="jdbc:sybase:Tds:tiger:5000/hbxs";
private static String user="sa";
private static String pwd="";
public static Connection CreateConn()
{
try
{
Class.forName(DBDriver);
Connection conn=DriverManager.getConnection(url,user,pwd);
return conn;
}
catch(Exception e)
{
System.out.println(e.toString());
}
return null;
}
}
//以下是
Jsp1
JBuilder Generated JSP
调试就错误?什么原因?去掉
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from hb_cig_code");
rs.close();
stmt.close();
con.close();
就可以通过?难道这个地方错了吗?
|
Connection con=login.CreateConn();
这句话取出的connection可能是null
这句话取出的connection可能是null
|
没错,根据错误信息看,应该是connection为null值了。
在Statement stmt=con.createStatement();之前加上一个判断吧
在Statement stmt=con.createStatement();之前加上一个判断吧
|
qin.DBConnQ
没看到
package qin
没看到
package qin