日期:2014-05-20 浏览次数:20852 次
package practice;
/*test*/
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.List;
import java.util.ArrayList;
import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
public static void main(String[]args){
String s;
int t = 0;
String[] sa=new String[5];
List data = new ArrayList();
try{
BufferedReader in =new BufferedReader(new FileReader("src/db.properties"));
while((s=in.readLine())!=null){
sa[t] =s.substring(0);
t++;
}
}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
/*connect the DB*/
String url = "jdbc:mysql://"+sa[0]+":"+sa[1]+"/"+sa[2];
String username = sa[3];
String password = sa[4];
Connection conn = null;
Statement stmt = null;
try{
conn = DriverManager.getConnection(url, username, password);
stmt = conn.createStatement();
}catch (SQLException e1) {
e1.printStackTrace();
}
/*put data in DB*/
File file = new File("D:\\HW3\\HW3\\data\\student.txt");
FileInputStream fis = null;
try {
fis = new FileInputStream(file);