?? filereadertest.java~7~
字號:
package net.bishe.file;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.sql.*; // JDBC package
import com.microsoft.jdbc.sqlserver.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Hashtable;
public class FileReaderTest {
public static void main(String[] args) throws Exception {
FileReaderTest test=new FileReaderTest();
try
{
test.readLineFile("d:\\","Winpy1.txt");
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void readLineFile(String filePath, String fileName)
throws IOException
, SQLException {
Connection con;
Statement stat=null;
ResultSet rs;
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:sjy", "", "");
stat = con.createStatement();
}
catch (ClassNotFoundException e) {}
// Connetion con=DriverManager.getConnection("jdbc:odbc:sjy","","");
FileReader fr = new FileReader(filePath + fileName);
BufferedReader br = new BufferedReader(fr);
String line = br.readLine();
while (line != null)
{
// System.out.println(line);
line = br.readLine();
if(line!=null)
{
String hanzi=line.substring(0,1);
String pinyin=line.substring(1,line.length());
// System.out.println(hanzi);
// System.out.println(pinyin);
String insertstr="insert into pinyin (hanzi,pinyin) values ('"+hanzi+"','"+pinyin+"')";
System.out.println(insertstr);
try
{
stat.execute(insertstr);
}
catch (SQLException e3)
{
// TODO Auto-generated catch block
e3.printStackTrace();
}
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -