I have learned how to create tables and add, delete, modify, and query tables on the SQLite console interface. The following describes how to use Java to operate the SQLite database.
1. Use eclipse in the development environment, create a Java project mysqlitetest, and create a class testsqlite. Java
2. Download The jdbc of the SQLite database. Here is the URL of a Chinese site:
Http://www.sqlite.com.cn/Upfiles/source/sqlitejdbc-v033-nested.tgz
3. decompress the downloaded package and obtain the jar package sqlitejdbc-v033-nested.jar. export it to the additional package path of mysqlitetest just created.
4. Write the following code:
import java.sql. *;
import org.sqlite.JDBC;
public class TestSQLite
{
public static void main (String [] args)
{
try
{
// JDBC for SQLite
Class.forName ("org.sqlite.JDBC");
// Establish a connection to the database name test.db.
Connection conn = DriverManager.getConnection ("jdbc: sqlite: / d: /test.db");
Statement stat = conn.createStatement ();
stat.executeUpdate ("create table user (name varchar (20), salary int);"); // Create the user table
stat.executeUpdate ("insert into user values ('LiSi', 7800);"); // Insert data
stat.executeUpdate ("insert into user values ('WangWu', 5800);");
stat.executeUpdate ("insert into user values ('Test', 9100);");
ResultSet rs = stat.executeQuery ("select * from user;"); // Query data
while (rs.next ()) {// Print out the query data
System.out.print ("name =" + rs.getString ("name") + ""); // Column property one
System.out.println ("salary =" + rs.getString ("salary")); // Column property two
}
rs.close ();
conn.close (); // End the database connection
}
catch (Exception e)
{
e.printStackTrace ();
}
}
}
The running result is as follows:
Name = Lisi salary = 7800
Name = wangwu salary = 5800
Name = zhaoliu salary = 9100
This example program is available in Baidu encyclopedia. We can see that two statements are used to connect to the database. create a table in the SQL database and insert the data for query. This is the same as using JDBC to operate the access/sqlserver database, but with a different driver when connecting to the database
The following describes how to apply it to a web program for user registration and login. Registration is actually a data table insertion Operation, and login is a table query operation.
References:
1. http://baike.baidu.com/view/19310.htm
2. http://secyaher.blog.163.com/blog/static/38955772010102772217537/