SQL Problem
Hi,
I am new to java so apologises if I am doing something stupid.
Ok I have a text file called access.log what I am trying to do is break the file into tokens using StreamTokenizer and then store the tokens in a multiple dimensional array. I then want to write the elements to an access database file using an insert statement. However when I execute my code it only adds one of the elements to each record set and leaves the rest blank it is also not the first element. I know that the file is being broken into tokens properly and stored in the array properly because I can print to the screen(have commented the lines out in my code that I used to test this) Any help would be appreciated.
import java.io.*;
import java.io.StreamTokenizer.*;
import java.sql.*;
publicclass TestAgain{
public TestAgain()throws Exception{
FileReader log =new FileReader("logs/access.log");
BufferedReader bufflog =new BufferedReader(log);
StreamTokenizer stlog =new StreamTokenizer(bufflog);
int j = 0;
int k = 0;
String [][] process;
process =new String [61][];
stlog.resetSyntax();
stlog.whitespaceChars(34, 34);
stlog.whitespaceChars(43, 43);
stlog.whitespaceChars(45, 45);
stlog.whitespaceChars(91, 91);
stlog.whitespaceChars(93, 93);
stlog.wordChars(32, 33);
stlog.wordChars(35, 42);
stlog.wordChars(44, 44);
stlog.wordChars(46, 90);
stlog.wordChars(92, 92);
stlog.wordChars(94, 125);
stlog.eolIsSignificant(false);
int x = 0;
boolean eof =false;
do{
int token = stlog.nextToken();
switch(token){
case StreamTokenizer.TT_EOF:
//System.out.println(x);
eof =true;
break;
case StreamTokenizer.TT_EOL:
j++;
k = 0;
//x++;
break;
case StreamTokenizer.TT_WORD:
process[j] =new String[13];
process [j][k] = stlog.sval;
//System.out.println(process[j][k]);
k++;
break;
default:
if (token =='!') eof =true;
}
}while (!eof);
for(int l =0; l< 61; l++)
do{
String data ="jdbc:odbc:LogFiles1";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection(data,"","");
PreparedStatement prep2 = conn.prepareStatement(
"INSERT INTO Logs VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
prep2.setString(1, process[l][0]);
prep2.setString(2, process[l][1]);
prep2.setString(3, process[l][2]);
prep2.setString(4, process[l][3]);
prep2.setString(5, process[l][4]);
prep2.setString(6, process[l][5]);
prep2.setString(7, process[l][6]);
prep2.setString(8, process[l][7]);
prep2.setString(9, process[l][8]);
prep2.setString(10, process[l][9]);
prep2.setString(11, process[l][10]);
prep2.setString(12, process[l][11]);
prep2.setString(13, process[l][12]);
prep2.executeUpdate();
conn.close();
}catch (SQLException sqe){
System.out.println("SQL Error: " + sqe.getMessage());
}catch (ClassNotFoundException cnfe){
System.out.println(cnfe.getMessage());
}
}while (j < 61);
}
publicstaticvoid main(String[] arguments)throws Exception{
TestAgain ta =new TestAgain();
}
}

