Java generates db files for ios and Android

In order to optimize the performance of the client, some mysql data tables are generated into db files for the client to use

<dependency>
  <groupId>org.xerial</groupId>
  <artifactId>sqlite-jdbc</artifactId>
  <version>3.23.1</version>
</dependency>

 

private static String Drivde="org.sqlite.JDBC";
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Class.forName(Drivde);// Load the driver and connect to the jdbc of sqlite
            String path = "D:\\exam\\preloading\\";
            String url = "jdbc:sqlite:" + path + "data.db";
            Connection connection=DriverManager.getConnection(url);//Connect to the database zhou. db, if it does not exist, create
            Statement statement=connection.createStatement(); //Create a connection object, which is an important interface for operating databases in Java.
            String sql="create table tables(name varchar(20),pwd varchar(20)) "; 
            statement.executeUpdate("drop table if exists tables");//Determine whether there are tables. Delete if there are
           statement.executeUpdate(sql); //Create a database
           statement.executeUpdate("insert into tables values('zhou','156546')");//Insert data into the database
           ResultSet rSet=statement.executeQuery("select*from tables");//Search the database and put the searched data into the data set ResultSet
           while (rSet.next()) {//Traverse this data set
               System.out.println("Name:"+rSet.getString(1) );//Sequential output can also be written like this rSet.getString("name")
               System.out.println("Password:"+rSet.getString("pwd"));
           }
           rSet.close();//Close data Set
           connection.close();//Close the database connection
       } catch (Exception e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
   }

Guess you like

Origin blog.csdn.net/YINZONGCHAO/article/details/99839001