小弟初学java
就是在做简单编程的时候 用
stmt.executeQuery的时候发生报错Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
stmt.executeQuery("select * from a")能把获得的东西显示在table上
但是加了stmt.executeQuery("select * from a where id='1'")就报错了求教了,谢谢

解决方案 »

  1.   

    报错为
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at javax.swing.JTable$1.getValueAt(Unknown Source)
    at javax.swing.JTable.getValueAt(Unknown Source)
    at javax.swing.JTable.prepareRenderer(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
    at javax.swing.plaf.ComponentUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JViewport.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
    at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    at java.awt.Container.paint(Unknown Source)
    at sun.awt.RepaintArea.paintComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
      

  2.   

    空指针异常, 检查一下查询有没有记录产生,还有在ResultSet中下标是从1开始,而数组则是从0开始,看看会不会是这个问题引起的.
      

  3.   

    stmt.executeQuery("select * from a where id='1'");
    我印象中这句好像应该这么写的.
    stmt.executeQuery("select * from a where id='"+1+"'");
    楼主可以参考,我也不确定哈.
    学习中...
      

  4.   

    stmt.executeQuery("select * from a where id=1");
    id应该是int型的吧,你那样写是String
      

  5.   

    我感觉应该这样 因为id是数字类型的不是字符串
    stmt.executeQuery("select * from a where id=1");
    仅供参考 
      

  6.   

    记得access里有区别,其他的数据库怎么写都行
      

  7.   

    不是数据库的错误,是swing的错误,看下是否jtable没有初始化完毕就开始对它进行操作了,是否每次拿jtable的引用都重新new了。
      

  8.   


    谢谢。做个DefaultTableModel就行了。不是数据库问题