?? ipinfotodb.java~47~
字號(hào):
package tsinghuaip;
import java.sql.*;
import java.util.*;
import java.io.*;
public class IPInfoToDB {
private String strTxtFileName; //IP地址文本文件名
private Connection conn = null;
private ResultSet rs = null;
private Statement stmt = null;
public IPInfoToDB() {
strTxtFileName = new String();
}
//設(shè)置文本文件名
public void SetTxtFileName(String strFileName) {
strTxtFileName = strFileName;
}
public void SaveIPToDB() throws Exception {
String strSeparator = "|"; //the separator of the text file field
String strTmp = "";
//進(jìn)行數(shù)據(jù)庫(kù)得連接
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://localhost:1433;" +
"DatabaseName=CampusIP";
conn = DriverManager.getConnection(url, "sa", "");
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
//從文本文件中讀取數(shù)據(jù)
BufferedReader inTxt = new BufferedReader(new FileReader(
strTxtFileName));
while ( (strTmp = inTxt.readLine()) != null) {
StringTokenizer strToken = new StringTokenizer(strTmp, "|");
String arrTmp[];
arrTmp = new String[3];
for (int i = 0; i < 3; i++)
arrTmp[i] = new String("");
int index = 0;
while (strToken.hasMoreElements()) {
strTmp = (String) strToken.nextElement();
strTmp = strTmp.trim();
arrTmp[index++] = strTmp;
}
//下面就是將這些數(shù)據(jù)寫進(jìn)數(shù)據(jù)庫(kù)
String SQL =
"insert IPInfo(STARTIP,ENDIP,LOCAL) "
+ " values('" + arrTmp[0] + "', '"
+ arrTmp[1] + "','"
+ arrTmp[2] + "')";
stmt.execute(SQL);
}
rs.close();
stmt.close();
conn.close();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -