Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
IPInfoToDB.java
Package: Java.rar [view]
Upload User: liming9091
Upload Date: 2014-10-27
Package Size: 3376k
Code Size: 2k
Category:
Java Develop
Development Platform:
Java
- package tsinghuaip;
- import java.sql.*;
- import java.util.*;
- import java.io.*;
- public class IPInfoToDB {
- private String strTxtFileName; //IP地址文本文件名
- private Connection conn = null;
- private Statement stmt = null;
- public IPInfoToDB() {
- strTxtFileName = new String();
- }
- //设置文本文件名
- public void SetTxtFileName(String strFileName) {
- strTxtFileName = strFileName;
- }
- public void SaveIPToDB() throws Exception {
- String strSeparator = "|"; //the separator of the text file field
- String strTmp = "";
- //进行数据库得连接
- 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);
- //从文本文件中读取数据
- 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;
- }
- //下面就是将这些数据写进数据库
- String SQL =
- "insert IPInfo(STARTIP,ENDIP,LOCAL) "
- + " values('" + arrTmp[0] + "', '"
- + arrTmp[1] + "','"
- + arrTmp[2] + "')";
- stmt.execute(SQL);
- }
- stmt.close();
- conn.close();
- }
- }