SoFunction
Updated on 2025-03-09

Android reads excel into sqlite3 database through jxl


package .day20140228;

import ;
import ;
import ;
import ;
import ;
import ;

import ;
import ;
import ;

public class DictExcelDemo {
 public static void main(String[] args) {
  DictExcelDemo ded = new DictExcelDemo();
  Connection conn = ();
  ded.readExcel_(conn);
 }

 private Connection getConnection(){
  Connection conn = null;
  try {
   ("");
   conn = ("jdbc:sqlite:");
   Statement stat = ();
("create  table if not exists dictionary(enword varchar(200), cnword varchar(200));");// Create a table with two columns

  } catch (ClassNotFoundException e) {
   ();
  } catch (SQLException e) {
   ();
  }
  return conn;
 }

 private void readExcel_(Connection conn) {
  try {
   Workbook book = (new File(""));
   PreparedStatement prep = ("insert into dictionary(enword,cnword) values(?,?);");

   for (int a = 0; a < 26; a++) {
// Get the first worksheet object
    Sheet sheet = (a);
// Get the cell of the first column and the first row
// Get the cell of the first column and the first row
int columnum = ();// Get the number of columns
int rownum = ();// Get the number of rows
for (int i = 1; i < rownum; i++)// Loop for reading and writing
{// OK
     String key = "";
     String value = "";
for (int j = 0; j < columnnum; j++) {// Column
      Cell cell1 = (j, i);
      String result = ();
      if (j == 0) {
       key += result;
      } else {
       value += result;
      }
     }
     // (key+"=="+value);
     (1, key);
     (2, value);
     ();
    }
   }
   (false);
   ();
   (true);
   ();
   ();
  } catch (Exception e) {
   (e);
  }
 }
}