java - sql command not properly ended (where is my mistakes) -


i hope receive answer time

i wrote below code don't know mistake seem correct think

this code should insert more million records oracle xe wrote single insert statement when execute preparedstatement 1 one it's run took 6 hours !!!!!! because forced use thread.sleep()

    package tokenizing; import java.sql.*; import java.util.stringtokenizer;  public class tokenextraction2 {       public static void main(string[] args) throws exception {         string mytext[]=new string[2276];         jdbc db=new jdbc();         string st1=null;         int i=0;         int j=0;         string tokens[][]=new string [3000000][2];         st1="select ntext newstext ";         resultset result=db.select(st1);         while(result.next())         {             mytext[i]=result.getstring("ntext");             ++i;         }         db.closedb();         i=0;         stringbuilder st= new stringbuilder("insert tokens5(token,tokenlength) values");         while(i<2276)         {              stringtokenizer s=new stringtokenizer(mytext[i]," 0123456789*./»«،~!@#$%^&()_-\"+=:;|<>?“؟”’{}[]‘,\\\t\n\r\fabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz...—`—ـ؛–…_");             while(s.hasmoretokens()){                 string key=s.nexttoken();                 tokens[j][0]=key;                 tokens[j][1]=(key.length())+"";                 st.append("(?,?)");                 if( i<2276 && s.hasmoretokens())                 st.append(", ");                 else                 st.append(";");                 //db.insert(st, key, key.length());                 //db.closedb();                 system.out.println(key+"\t");                       j++;             }             system.out.println("num of news is: "+i);             system.out.println("*****************************************************************************************");             system.out.println("num of tokens is: "+j);             system.out.println("next news"+"\t");             //j=0;              i++;         }          system.out.println(st);         int k=0;           class.forname("oracle.jdbc.driver.oracledriver") ;         connection  con = drivermanager.getconnection("jdbc:oracle:thin:@localhost:1521:xe","albaloo","myjava123");         preparedstatement ps=con.preparestatement(st.tostring());     //  con.setautocommit(false);         //j=1;         i=0;         //j=j-286;         while(k<j)         {              i=i+1;                  ps.setstring(i, tokens[k][0]);              system.out.println(i);                 i=i+1;                 ps.setint(i,integer.parseint(tokens[k][1]));                  system.out.println(k+2);                  k++;           }          ps.executeupdate();     //con.commit(); }          } 

you seem have trying insert multiple rows single insert statement, passing multiple sets of values; st appears end as:

insert tokens5(token,tokenlength) values (?,?), (?,?);(?,?), ...;` 

with thousands of value pair placeholder. can't pass multiple sets of values that. oracle isn't expecting comma after first (?,?), hence ora-00933 error. have multiple semi-colons in there you're putting 1 each time around i while loop. mark rotteveel pointed out, should not have oracle jdbc doesn't allow multiple statements.

you might better off implementing string tokenizer function on database , doing single insert ... select newstext, rather pulling data out, converting , pushing back. should @ least batch updates though. pass tokens array argument stored procedure, example.

i'm struggling understand you're doing though, looks you're splitting string on pretty character, doesn't leave actual keys, it? it's hard follow though...


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -