日期:2014-05-20 浏览次数:20746 次
import java.io.File;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.sql.*;
import java.lang.*;
public class test4 {
public static void main(String[] args) throws Exception {
Class.forName("org.sqlite.JDBC");
Connection c = DriverManager.getConnection("jdbc:sqlite:D:\\applicationbaggage\\Notepad++\\test4.db3");
Statement s = c.createStatement();
s.executeUpdate("drop table if exists apply");
s.executeUpdate("create table apply(sID int ,cName string,major string,decision string) ");
String pathname = "dbapply.txt";
File filename = new File(pathname);
InputStreamReader reader = new InputStreamReader(
new FileInputStream(filename));
BufferedReader br = new BufferedReader(reader);
String line = "";
line = br.readLine();
while (line != null) {
String []strarray = line.split(",");
if(strarray[0] != null){
s.executeUpdate("insert into apply values(Integer.parseInt(strarray[0]),strarray[1],strarray[2],strarray[3])");
line = br.readLine();
}
}
}
}
s.executeUpdate("insert into apply values(" + Integer.parseInt(strarray[0]) + "," + strarray[1] + "," + strarray[2] + "," + strarray[3] + ")");另外推荐用PreparedStatement