Results 1 to 5 of 5
  1. #1
    sara777's Avatar
    sara777 is offline Member
    Join Date
    Jul 2013
    Location
    The other side world
    Posts
    2
    Rep Power
    0

    Unhappy sql command not properly ended

    Hi all
    i wrote below code and get error "sql command not properly ended"

    plz help me to solve it
    in addition i wrote this code by single insert statement when execute PreparedStatement one by one
    but it's run took 6 hours !!!!!!
    because i was forced use thread.sleep()

    Java Code:
        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 from NEWSTEXT ";
            ResultSet result=db.select(st1);
            while(result.next())
            {
                myText[i]=result.getString("ntext");
                ++i;
            }
            db.closedb();
            i=0;
            StringBuilder st= new StringBuilder("insert into 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();
    }
    
    
    
    
    
    
    
    
    
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: sql command not properly ended

    Since you're printing out the query in there then it might be an idea to post that here.
    Also, no point using a PreparedStatement if all you are going to do is concatenate any variables in anyway.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,050
    Rep Power
    6

    Default Re: sql command not properly ended

    Quote Originally Posted by Tolls View Post
    Also, no point using a PreparedStatement if all you are going to do is concatenate any variables in anyway.
    I don't get that one; the code is using parameters, I don't see any values being directly embedded into the query.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default Re: sql command not properly ended

    Oh...arse.
    I completely missied that while loop!

    Oopsie...

    My bit about shoing us what the SQL string looks like stands, though.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    sara777's Avatar
    sara777 is offline Member
    Join Date
    Jul 2013
    Location
    The other side world
    Posts
    2
    Rep Power
    0

    Default Re: sql command not properly ended

    thanx all friends !!
    i solve my problem
    by use batch

Similar Threads

  1. Letting my program command the command prompt
    By Smokey. in forum Threads and Synchronization
    Replies: 4
    Last Post: 03-29-2011, 11:34 PM
  2. Twitter Open-ended Biographical Search Engine
    By mobiletimes in forum Java Software
    Replies: 0
    Last Post: 11-23-2010, 11:26 AM
  3. how to getText() properly?
    By javamula in forum New To Java
    Replies: 12
    Last Post: 09-16-2009, 05:45 AM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 12:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •