溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

發(fā)布時(shí)間:2021-03-16 17:12:36 來源:億速云 閱讀:429 作者:TREX 欄目:數(shù)據(jù)庫

本篇內(nèi)容介紹了“IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫”的有關(guān)知識(shí),在實(shí)際案例的操作過程中,不少人都會(huì)遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

工具列表:

1.Sqlite

2. SQLiteStudio

3. IntellJ

4. sqlite-jdbc-3.32.3.2.jar

運(yùn)行結(jié)果先睹為快:

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

下載安裝IntellJ

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

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

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

下載Sqlite開發(fā)工具

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

解壓后直接可以運(yùn)行,無需安裝。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

創(chuàng)建數(shù)據(jù)庫文件

創(chuàng)建studio.sqlite名稱的數(shù)據(jù)庫文件。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

注釋:如果出現(xiàn)無法生成的現(xiàn)象,在“sqlite>”后輸入任意非空字符后回車然后Ctrl+C取消即可生成studio.sqlite文件。(.sqlite,.db后綴數(shù)據(jù)庫文件均可識(shí)別。)

此處如果只創(chuàng)建一個(gè)空白的文件,也可以用修改后綴的方法直接新建一個(gè)*.db文件。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

數(shù)據(jù)庫文件寫入數(shù)據(jù)

這個(gè)網(wǎng)絡(luò)地址可以下載SQLiteStudio,還有使用教程。可以方便的錄入數(shù)據(jù)。

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

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

數(shù)據(jù)庫錄入數(shù)據(jù)

錄入示例數(shù)據(jù)和字段完成如下所示:

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

進(jìn)入IntellJ配置數(shù)據(jù)庫

此時(shí)發(fā)現(xiàn)Tool Windows中沒有Database選項(xiàng),需要安裝Database工具包。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

File-》Settings-》Plugins

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

選擇Plugins,搜索框搜索database,安裝“Database Navigator”,然后重啟Intellj應(yīng)用。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

重啟后,左邊框會(huì)出現(xiàn)“DB Browser”選項(xiàng)。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

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. 數(shù)據(jù)庫操作函數(shù)中存在異常,因此需要包含ClassNotFoundException, SQLException,參考編譯器調(diào)試添加即可。

運(yùn)行結(jié)果如下所示:

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

附錄:

問題一:數(shù)據(jù)庫加載失敗

出現(xiàn)如下錯(cuò)誤,可能是沒有添加jar包導(dǎo)致。sqlite-jdbc-3.32.3.2.jar

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

file-》Project structure-》

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

添加sqlite-jdbc-3.32.3.2.jar,記得勾選。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

問題二:

如下URL對應(yīng)的就是數(shù)據(jù)庫的路徑和名稱。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

問題三:無法連接數(shù)據(jù)庫

查看數(shù)據(jù)庫url名稱,并且運(yùn)行代碼之前確保數(shù)據(jù)庫是disconnect狀態(tài)。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

題四:讀取表信息失敗

如下為數(shù)據(jù)庫創(chuàng)建的表名字不對應(yīng),使用SQLiteStudio打開數(shù)據(jù)庫文件查看DLL(參考上面的圖)修改為正確的名稱即可。

IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫

“IntellJ Idea 2020版怎么添加sqlite數(shù)據(jù)庫”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI