【移動GIS】sqlite的使用(一)

來源:互聯網
上載者:User

先粘貼下百度百科的介紹:  

   SQLite,是一款輕型的資料庫,是遵守ACID[1]的關係型資料庫管理系統,它包含在一個相對小的C庫中,不像常見的客戶-伺服器範例,SQLite引擎不是個程式與之通訊的獨立進程,而是串連到程式中成為它的一個主要部分。所以主要的通訊協定是在程式設計語言內的直接API調用。這在消耗總量、延遲時間和整體簡單性上有積極的作用。整個資料庫(定義、表、索引和資料本身)都在宿主主機上儲存在一個單一的檔案中。它的簡單的設計是通過在開始一個事務的時候鎖定整個資料檔案而完成的。

  

說到底,SQLite這個資料庫特點是:

          1.小。不僅是佔用空間小,而且在使用過程中效率也很高,佔用記憶體小。

          2.方便。Sqlite資料產生之後是單個檔案,此檔案包含了資料庫所有的東西,你可用隨身碟什麼的隨便拷走。

          3.跨平台。因為人家是用C寫的,而且是開源的,所有什麼windows linux  macos等作業系統都支援。

          4.支援常用SQL。如果你用過mysql sqlserver 或oracle,那麼使用sqlite會非常容易上手,它支援一些基本的sql語句,還支援事務哦。

          5.沒有安全認證。sqltite產生一個資料庫檔案之後,任何人都可以查看裡面的表資訊,它不需要輸入使用者名稱或密碼什麼的,這是缺點也是優點,做了太多了驗證就不方便了

 

那麼在普通用java操作需要下載sqlite JDBC,那麼該如何操作呢?看了下面的例子你就會明白了:

 

           

import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;public class Sample{  public static void main(String[] args) throws ClassNotFoundException  {    // load the sqlite-JDBC driver using the current class loader    Class.forName("org.sqlite.JDBC");    Connection connection = null;    try    {      // create a database connection      connection = DriverManager.getConnection("jdbc:sqlite:sample.db");      Statement statement = connection.createStatement();      statement.setQueryTimeout(30);  // set timeout to 30 sec.      statement.executeUpdate("drop table if exists person");      statement.executeUpdate("create table person (id integer, name string)");      statement.executeUpdate("insert into person values(1, 'leo')");      statement.executeUpdate("insert into person values(2, 'yui')");      ResultSet rs = statement.executeQuery("select * from person");      while(rs.next())      {        // read the result set        System.out.println("name = " + rs.getString("name"));        System.out.println("id = " + rs.getInt("id"));      }    }    catch(SQLException e)    {      // if the error message is "out of memory",       // it probably means no database file is found      System.err.println(e.getMessage());    }    finally    {      try      {        if(connection != null)          connection.close();      }      catch(SQLException e)      {        // connection close failed.        System.err.println(e);      }    }  }}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.