简体   繁体   English

java.sql.SQLException:找不到适用于jdbc:sqlite:db / Fakturi.sqlite的驱动程序

[英]java.sql.SQLException: No suitable driver found for jdbc:sqlite:db/Fakturi.sqlite

I'm Using Java SWING + SQLite. 我正在使用Java SWING + SQLite。 When I export executable jar (option Extract required libraries into generated JAR) and try to run, there is error: ....>java -jar g222.jar java.sql.SQLException: No suitable driver found for jdbc:sqlite:db/Fakturi.sqlit e 当我导出可执行jar(选项将所需的库提取到生成的JAR中)并尝试运行时,出现错误: ....>java -jar g222.jar java.sql.SQLException: No suitable driver found for jdbc:sqlite:db/Fakturi.sqlit e

If I run it under Eclipse - it's works. 如果我在Eclipse下运行它,则可以正常工作。 Here is my code: 这是我的代码:

public class MainFrame extends JFrame {

    private JPanel contentPane;
    private JTextField textField_6;
    private JTextField textField_7;



    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MainFrame frame = new MainFrame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     * @throws SQLException 
     */
    public MainFrame() throws SQLException {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 643, 298);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setBorder(new EmptyBorder(5, 5, 5, 5));
        panel.setBounds(10, 11, 670, 287);
        contentPane.add(panel);


        JPanel panel_2 = new JPanel();
        panel_2.setLayout(null);
        panel_2.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
        panel_2.setBounds(196, 51, 249, 100);
        panel.add(panel_2);

        JLabel label_21 = new JLabel("\u0411\u0440\u043E\u0439:");
        label_21.setBounds(10, 40, 128, 16);
        panel_2.add(label_21);

        textField_6 = new JTextField();
        textField_6.setText("0");
        textField_6.setHorizontalAlignment(SwingConstants.RIGHT);
        textField_6.setEditable(false);
        textField_6.setColumns(10);
        textField_6.setBackground(new Color(135, 206, 250));
        textField_6.setBounds(150, 37, 42, 22);
        panel_2.add(textField_6);

        JLabel label_22 = new JLabel("\u041E\u0431\u0449\u0430 \u0441\u0442\u043E\u0439\u043D\u043E\u0441\u0442 \u0441 \u0414\u0414\u0421:");
        label_22.setBounds(10, 70, 135, 16);
        panel_2.add(label_22);

        textField_7 = new JTextField();
        textField_7.setText("0.00 \u043B\u0432.");
        textField_7.setHorizontalAlignment(SwingConstants.RIGHT);
        textField_7.setForeground(Color.RED);
        textField_7.setFont(new Font("Tahoma", Font.BOLD, 11));
        textField_7.setEditable(false);
        textField_7.setColumns(10);
        textField_7.setBackground(new Color(255, 160, 122));
        textField_7.setBounds(150, 67, 87, 22);
        panel_2.add(textField_7);

        JLabel label_23 = new JLabel("\u041F\u0440\u043E\u0444\u043E\u0440\u043C\u0430 \u0444\u0430\u043A\u0442\u0443\u0440\u0438");
        label_23.setHorizontalAlignment(SwingConstants.CENTER);
        label_23.setForeground(Color.GRAY);
        label_23.setBounds(6, 6, 224, 14);
        panel_2.add(label_23);

        String danOsnInvoices = ConnectionToDb.stmSqlQuery("SELECT printf('%.2f', ROUND(sum(quantity*price), 2)) FROM invoices_out WHERE number = '0000000001'");
        textField_6.setText(danOsnInvoices);

    }
}

And Connection class is: 连接类为:

public class ConnectionToDb {

    public Connection conn = null;
    public static final String DBURL = "jdbc:sqlite:db/Fakturi.sqlite";

    public static Connection connectDb() throws ClassNotFoundException,SQLException {
        Class.forName("org.sqlite.JDBC");
        Connection conn = DriverManager.getConnection(DBURL);
        return conn;
    }

    public static String dmlSqlQuery(String value) throws SQLException, ClassNotFoundException {

            Statement stmt;
            String result = null;

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

                Connection c = DriverManager.getConnection(DBURL);
                c.setAutoCommit(false);

                stmt = c.createStatement();
                String sql = value;
                stmt.executeUpdate(sql);

                stmt.close();
                c.commit();
                c.close();

            return result;
        }

    public static String stmSqlQuery(String value) throws SQLException {

        String result = null;
        DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
        Connection con = DriverManager.getConnection(DBURL);

        Statement statement = con.createStatement();

        // Enables us to retrieve values as if querying from a table
        ResultSet rs = statement.executeQuery(value);

        if (rs.next()) {
            result = rs.getString(1); // get first column returned
        }

        rs.close();
        statement.close();
        con.close();
        return result;
    }
}

I can't understand Why this error shows. 我不明白为什么显示此错误。

SOLVED: I just add: ConnectionToDb.connectDb(); 解决:我只添加: ConnectionToDb.connectDb(); before any SQL queries. 在执行任何SQL查询之前。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException:找不到适用于jdbc:sqlite的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:sqlite java.sql.SQLException: No suitable driver found for jdbc:sqlite:D:\login_signup\src\main\Database\login_info.db - java.sql.SQLException: No suitable driver found for jdbc:sqlite:D:\login_signup\src\main\Database\login_info.db java.sql.SQLException:找不到适用于jdbc:microsoft的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:microsoft java.sql.SQLException:找不到适合jdbc的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc 错误:java.sql.SQLException:未找到适合jdbc:sqlserver的驱动程序 - Error: java.sql.SQLException: No suitable driver found for jdbc:sqlserver java.sql.SQLException:找不到合适的驱动程序jdbc:oracle:thin - java.sql.SQLException: No suitable driver found jdbc:oracle:thin java.sql.SQLException:找不到适合jdbc:oracle:thin的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:oracle:thin java.sql.SQLException:找不到适用于jdbc:derby的驱动程序: - java.sql.SQLException: No suitable driver found for jdbc:derby: java.sql.SQLException:找不到适用于jdbc:mysql的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:mysql java.sql.SQLException:找不到适用于jdbc:sqlserver的驱动程序: - java.sql.SQLException: No suitable driver found for jdbc:sqlserver:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM