sqlite的操作

來源:互聯網
上載者:User

標籤:account   blog   lock   個人   服務   exe   while   載入   try   

學習android的過程中,用到了sqlite資料庫,個人開發的一款app已經儲存了許多的資料,但是一次意外導致資料庫被刪除。我想著增加一個功能,資料庫定期同步到主機上,在做這個功能之前,有必要瞭解一些基礎知識。

1. sqlite作為一款輕量級的嵌入式資料庫,其資料存放區在db檔案中,我們直接對db檔案操作就可以改變其資料。不像sqlserver等大型關係型資料庫,一定要串連資料庫伺服器,才能操作。下面是一段java代碼串連sqlite資料庫檔案並處理,使用了java的sqlite_jdbc。

package com.gs.summer.test.sql;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class SqliteJdbc {          public static void main(String[] args) throws SQLException {            // 載入驅動            try {                Class.forName("org.sqlite.JDBC");            } catch (ClassNotFoundException e) {                // TODO Auto-generated catch block                // e.printStackTrace();                System.out.println("資料庫驅動未找到!");            }            // 得到串連 會在你所填寫的目錄建一個你命名的檔案資料庫            Connection conn;                conn = DriverManager.getConnection("jdbc:sqlite:C:/Users/gaosong/Desktop/account_db",null,null);                // 設定自動認可為false                conn.setAutoCommit(false);                Statement stmt = conn.createStatement();                                //判斷表是否存在                ResultSet rsTables = conn.getMetaData().getTables(null, null, "account_tb", null);                if(rsTables.next()){                    System.out.println("表存在,建立表的事情不要做了");                } else {                    System.out.println("表不存在");                }                // 得到結果集                ResultSet rs = stmt.executeQuery("select * from account_tb;");                            while (rs.next()) {                                     System.out.println("id = " + rs.getString("id"));                }                rs.close();                conn.close();                 }  }

2.圖形介面化管理工具

可以選擇一款試用多種資料庫類型的視圖介面管理器,強烈推薦使用navicat_premium

 

sqlite的操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.