java 执行数据库语句的问题。

[复制链接]
查看11 | 回复4 | 2013-6-22 15:29:49 | 显示全部楼层 |阅读模式
stmt没有初始化,stmt=null,调用stmt的executeQuery方法出现空指针异常。应该先初始化stmt,Class.forName("org.gjt.mm.mysql.Driver").newInstance(); String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicod e=true&characterEncoding=8859_1" //myDB为数据库名 Connection conn= DriverManager.getConnection(url); stmt = conn.createStament...
回复

使用道具 举报

千问 | 2013-6-22 15:29:49 | 显示全部楼层
stmt = conn.createStament();Connection conn=DriverManager.getConnection(url,user,pass) ? 你的哪里去了连接都没...
回复

使用道具 举报

千问 | 2013-6-22 15:29:49 | 显示全部楼层
sql语句写错了.查不到值,所以报空指针,应该是这样的....
回复

使用道具 举报

千问 | 2013-6-22 15:29:49 | 显示全部楼层
在这个方法中stmt是null而且我看你的sql="select Sno,password from STUDENT where Sno = name";应该是sql="select Sno,password from STUDENT where Sno ="+name;...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行