连接oracle数据库,为什么报错java.lang.NullPointerException。

gundam_king 2003-03-28 02:43:29
import java.sql.*;
class sql
{
private static Connection con=null;
private static Statement stmt=null;
private static ResultSet rs=null;
public static void main(String args[])
{
try
{
/* Test loading driver */

String driver = "oracle.jdbc.driver.OracleDriver";
System.out.println( "\n=> loading driver:" );
Class.forName( driver ).newInstance();
System.out.println( "OK" );

/* Test the connection */
String url = "jdbc:oracle:thin:@192.168.6.3:1521:JIVE";
con = DriverManager.getConnection(url, "system", "manager");
System.out.println( "\n=> connecting:" );
stmt=con.createStatement();
String sql = "select * from JIVEID";
String telphone = null;
while(rs.next())
{
telphone = rs.getString(1);
System.out.println(telphone);
}
con.close();
}
catch( Exception x )
{
System.err.println( x );
}
}
}
好像是在getConnection是有错,可是我的数据库密码和用户名都没有问题,为什么会这样?
...全文
359 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
runaway 2003-03-28
  • 打赏
  • 举报
回复
没有查询,rs 当然是null
gundam_king 2003-03-28
  • 打赏
  • 举报
回复
解决了
jcq 2003-03-28
  • 打赏
  • 举报
回复
首先是你要测试一下:
if(con!=null)
其次,你的
rs在什么时候打开的,应该要
rs = stmt.executeQuery(sql);吧
然后,测试;
if(rs!=null)
zhaoweiemail 2003-03-28
  • 打赏
  • 举报
回复
你加上oracle的数据库连接驱动了吗?

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧