SEVERE:null java.sql.SQLException

时间:2012-12-24 20:25:08

标签: java sqlite jtable sqlexception

  

可能重复:
  Connecting to SQLite Database Fails

我是Java的初学者

当我想在GUI界面中将SQLite的输出传递给JTable时,我得到了这个例外:

  

严重:空       java.sql.SQLException:没有为jdbc找到合适的驱动程序:sqlite:C:\ Users \ Amr \ Documents \ NetBeansProjects \ Project \ BillsDataBase.sqlite     在java.sql.DriverManager.getConnection(DriverManager.java:604)at   java.sql.DriverManager.getConnection(DriverManager.java:243)at   NewClass。(NewClass.java:22)at   NewClass $ 5.run(NewClass.java:342)at   java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)at   java.awt.EventQueue.dispatchEventImpl(EventQueue.java:721)at at   java.awt.EventQueue.access $ 200(EventQueue.java:103)at   java.awt.EventQueue $ 3.run(EventQueue.java:682)at   java.awt.EventQueue $ 3.run(EventQueue.java:680)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)     在java.awt.EventQueue.dispatchEvent(EventQueue.java:691)at   java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)     在   java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)     在   java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)     在   java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)     at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

代码:

public class NewClass extends javax.swing.JFrame {
    Connection conn = null;
    ResultSet rs = null;
    PreparedStatement pst = null;

    public NewClass() {     
        initComponents(); 
        try {
            conn = DriverManager.getConnection("jdbc:sqlite:C:\\Users\\Amr\\Documents\\NetBeansProjects\\Project\\BillsDataBase.sqlite");
        } catch (SQLException ex) {
            Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    private void Update_table(){
        try {
            String sql ="SELECT Amount, Type,Invoice FROM BillsDataBase";
            pst=conn.prepareStatement(sql);
            rs=pst.executeQuery();
            Table_Bills.setModel(DbUtils.resultSetToTableModel(rs));
        }
        catch(SQLException e){
            JOptionPane.showMessageDialog(null, e);
        }
    }

休息时,有一个名为Table_Bills

的表格

1 个答案:

答案 0 :(得分:1)

你成功完成了:

Class.forName("org.sqlite.JDBC");