如何使用 Java 连接到 SQLite [已关闭]

问题描述 投票:0回答:0

如何通过 JDBC 连接 SQLite 数据库。

代码:

import java.sql.*; 

public class Connect {  

    public static void connect() {  
        Connection conn = null;  
        try {  
            
            String url = "jdbc:sqlite:C:/sqlite/JTP.db";  
           
            conn = DriverManager.getConnection(url);  
              
            System.out.println("Connection to SQLite has been established.");  
              
        } catch (SQLException e) {  
            System.out.println(e.getMessage());  
        } finally {  
            try {  
                if (conn != null) {  
                    conn.close();  
                }  
            } catch (SQLException ex) {  
                System.out.println(ex.getMessage());  
            }  
        }  
    }  

    public static void main(String[] args) {  
        connect();  
    }  
}  

这会显示错误“没有合适的驱动程序”如何解决该问题。

Sqlite

https://www.tutorialspoint.com/sqlite/
爪哇 https://www.w3schools.com/java/ 数据库连接 https://www.javatpoint.com/java-jdbc

java sqlite jdbc sqlitejdbc
© www.soinside.com 2019 - 2024. All rights reserved.