this.pstmt=pstmt;
this.rs=rs;
try{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/mydatabase?useUnicode=true&characterEncoding=UTF-8";
conn=DriverManager.getConnection(url,"root","root");
pstmt=conn.createStatement();
rs=pstmt.executeQuery("select*from dictionary");
你这里的 this.rs还是null,所以,会抛nullPoint,应该把this.rs=rs; 这句放到rs=pstmt.executeQuery("select*from dictionary");
的后面,
还有,mdd.rs.getString("word")==tfind.getText()这个判断很有问题,String类的判断,这里最好用
mdd.rs.getString("word".equals(tfind.getText());
Java使用MySQL
最新推荐文章于 2024-09-18 23:16:13 发布
本文讨论了使用Java进行数据库操作时出现的NullPointerException问题,并给出了具体的解决办法。指出在执行SQL查询前应正确初始化结果集对象,避免空指针异常。同时,还提到了字符串比较时的常见错误及正确的做法。
2649

被折叠的 条评论
为什么被折叠?



