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