1. 程式人生 > 資料庫 >IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

工具列表:

1.Sqlite

2. SQLiteStudio

3. IntellJ

4. sqlite-jdbc-3.32.3.2.jar

執行結果先睹為快:

IntellJ Idea 2020版新增sqlite資料庫的方法

下載安裝IntellJ

直接到官網下載即可,新手建議不要下載最新的,一旦編譯器UI上有修改和教程對不上號,自己爬樓摸索比較話時間。當然也會有第一手的寶貴收穫。

https://www.jetbrains.com/idea/download/#section=windows

IntellJ Idea 2020版新增sqlite資料庫的方法

下載Sqlite開發工具

https://www.sqlite.org/download.html

解壓後直接可以執行,無需安裝。

IntellJ Idea 2020版新增sqlite資料庫的方法

建立資料庫檔案

建立studio.sqlite名稱的資料庫檔案。

IntellJ Idea 2020版新增sqlite資料庫的方法

註釋:如果出現無法生成的現象,在“sqlite>”後輸入任意非空字元後回車然後Ctrl+C取消即可生成studio.sqlite檔案。(.sqlite,.db字尾資料庫檔案均可識別。)

此處如果只建立一個空白的檔案,也可以用修改後綴的方法直接新建一個*.db檔案。

IntellJ Idea 2020版新增sqlite資料庫的方法

資料庫檔案寫入資料

這個網路地址可以下載SQLiteStudio,還有使用教程。可以方便的錄入資料。

http://www.xue51.com/soft/4831.html

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

資料庫錄入資料

錄入示例資料和欄位完成如下所示:

IntellJ Idea 2020版新增sqlite資料庫的方法

進入IntellJ配置資料庫

此時發現Tool Windows中沒有Database選項,需要安裝Database工具包。

IntellJ Idea 2020版新增sqlite資料庫的方法

File-》Settings-》Plugins

IntellJ Idea 2020版新增sqlite資料庫的方法

選擇Plugins,搜尋框搜尋database,安裝“Database Navigator”,然後重啟Intellj應用。

IntellJ Idea 2020版新增sqlite資料庫的方法

重啟後,左邊框會出現“DB Browser”選項。

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

java程式碼如下:

import java.sql.*;
 
public class database {
  public static void main(String[] arg) throws ClassNotFoundException,SQLException {
    System.out.println("database");
    Connection conn = null;
    ResultSet rs = null;
    Statement statement;
    Class.forName("org.sqlite.JDBC");//sqlite database name.
    conn = DriverManager.getConnection("jdbc:sqlite:F:\\codeZ\\database\\mysqlite1.sqlite");
    statement = conn.createStatement();
    rs = statement.executeQuery("SELECT * FROM demo"); //this is name of database list
    while (rs.next()){
      System.out.println("--------------------");
      System.out.print("id:"+rs.getString("id"));
      System.out.print("  name:"+rs.getString("name"));
      System.out.println("  age:"+rs.getString("age"));
    }
 
  }
}

注意:

1. 資料庫操作函式中存在異常,因此需要包含ClassNotFoundException,SQLException,參考編譯器除錯新增即可。

執行結果如下所示:

IntellJ Idea 2020版新增sqlite資料庫的方法

附錄:

問題一:資料庫載入失敗

出現如下錯誤,可能是沒有新增jar包導致。sqlite-jdbc-3.32.3.2.jar

IntellJ Idea 2020版新增sqlite資料庫的方法

file-》Project structure-》

IntellJ Idea 2020版新增sqlite資料庫的方法

IntellJ Idea 2020版新增sqlite資料庫的方法

新增sqlite-jdbc-3.32.3.2.jar,記得勾選。

IntellJ Idea 2020版新增sqlite資料庫的方法

問題二:

如下URL對應的就是資料庫的路徑和名稱。

IntellJ Idea 2020版新增sqlite資料庫的方法

問題三:無法連線資料庫

檢視資料庫url名稱,並且執行程式碼之前確保資料庫是disconnect狀態。

IntellJ Idea 2020版新增sqlite資料庫的方法

題四:讀取表資訊失敗

如下為資料庫建立的表名字不對應,使用SQLiteStudio開啟資料庫檔案檢視DLL(參考上面的圖)修改為正確的名稱即可。

IntellJ Idea 2020版新增sqlite資料庫的方法

到此這篇關於IntellJ Idea 2020版新增sqlite資料庫的方法的文章就介紹到這了,更多相關Idea新增sqlite資料庫內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!