Operation of SQLite

Source: Internet
Author: User
Tags sqlite sqlite database



In the process of learning Android, using the SQLite database, a personal development of an app has stored a lot of data, but one accident caused the database to be deleted. I want to add a function, the database is synchronized regularly to the host, before doing this function, it is necessary to understand some basic knowledge.



1. As a lightweight embedded database, SQLite's data is stored in a DB file, and we can change its data directly to the DB file. Unlike a large relational database such as SQL Server, you must connect to the database server to operate. Here is a section of Java code connected to the SQLite database file and processed, using the 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 {
          // load driver
          try {
              Class.forName ("org.sqlite.JDBC");
          } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              // e.printStackTrace ();
              System.out.println ("Database driver not found!");
          }
          // Get a connection, a file database named by you will be built in the directory you filled in
          Connection conn;

              conn = DriverManager.getConnection ("jdbc: sqlite: C: / Users / gaosong / Desktop / account_db", null, null);
              // Set automatic submission to false
              conn.setAutoCommit (false);
              Statement stmt = conn.createStatement ();
                
              // Determine whether the table exists
              ResultSet rsTables = conn.getMetaData (). GetTables (null, null, "account_tb", null);
              if (rsTables.next ()) {
                  System.out.println ("The table exists, don't do the thing to create the table");
              } else {
                  System.out.println ("Table does not exist");
              }

              // get the result set
              ResultSet rs = stmt.executeQuery ("select * from account_tb;");
            
              while (rs.next ()) {
                 
                  System.out.println ("id =" + rs.getString ("id"));
              }
              rs.close ();
              conn.close ();
         
      }

}

2. Graphical Interface management Tools



You can choose a view interface manager that tries a variety of database types, and it is highly recommended to use Navicat_premium






Operation of SQLite


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.