안녕하세요...
insert하는 부분을 잘 몰라서요
서버 폴더에 정보가 업데이트 되는데요
각기 다른 파일이 10개정도 업데이트 됩니다.
하나정도는 읽어서 insert 시키는 방법은 알겠는데요
다음파일 그 다음 파일을 순차적으로db에 insert 시키려면 어떻게 해야하나요?
파일은 text파일 입니다.
부탁드립니다.
-------------- main.java -----------------
package test;
import java.io.*;
import java.util.*;
public class Main
{
Database m_db;
public Main()
{
m_db = new Database();
m_db.DBDriver();
String str;
float aa[][] = new float[253][149];
try
{
BufferedReader reader = new BufferedReader(new FileReader("C:/Test/T3H_2007012800_1.txt,C:/Test/T3H_2007012800_1.txt"));
//StreamTokenizer tokens = new StreamTokenizer(reader);
//tokens.quoteChar(','); //','자를 구분하여 토큰한다.
int y =0;
while((str = reader.readLine()) != null)
{ //한 라인 읽기
StringTokenizer tokens = new StringTokenizer(str);
m_db.DBConn();
for(int x=0; x <=148 ; x++)
{
aa[y][x] = Float.parseFloat(tokens.nextToken(","));
System.out.println(y + "," + x + "= " +aa[y][x]);
m_db.DBinsert(y, x, Float.toString(aa[y][x]));
//System.out.println(y + "," + x + "= " +aa[y][x]);
}
//System.out.println(str); //그것을 출력한다
m_db.DBClose();
y++;
}
reader.close();
}catch(Exception e)
{
System.out.println("읽기 에러: " + e);
}
System.out.println(aa[0][0]);
}
public static void main(String[] args) throws IOException
{
//InputStreamReader reader = new InputStreamReader(new FileInputStream("C:/Test/Test/T3H_2007012800_1.txt"));
new Main();
}
}
----------------- database.java --------------------
package test;
import java.util.*;
import java.sql.*;
public class Database
{
Connection ora_conn = null;
PreparedStatement ora_pstmt = null;
String uri = "jdbc:oracle:thin:@121.123.200.123:1521:ispds";
String id = "affis";
String pass = "affis00";
String query = null;
public void AA()
{
System.out.println("aa");
}
public void DBDriver()
{
try
{
Class.forName("oracle.jdbc.OracleDriver");
System.out.println("드라이버 검색 성공!");
}
catch(ClassNotFoundException e)
{
System.err.println("error1 = " + e);
System.exit(1);
}
}
public void DBConn()
{
try
{
ora_conn = DriverManager.getConnection(uri,id,pass);
}
catch(SQLException e)
{
System.err.println("sql error = " + e);
System.exit(1);
}
}
public void DBinsert(int y, int x, String T3H)
{
query = "INSERT INTO \"TEST_WEATHER\" (x, y, T3H) VALUES("+ y +","+ x +"," + "'" + T3H + "')" ;
try
{
ora_pstmt = ora_conn.prepareStatement(query);
ResultSet ora_rs = ora_pstmt.executeQuery();
ora_pstmt.close();
}
catch(SQLException e)
{
System.err.println("sql error = " + e);
}
}
public void DBClose()
{
try
{
ora_conn.close();
}
catch(SQLException e)
{
System.err.println("sql error = " + e);
System.exit(1);
}
}
|