Page 1 of 2 12 LastLast
Results 1 to 20 of 23
  1. #1
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default Need Java Help ASAP

    Hey guys I am relatively new to JAVA and need help APAP.

    I am currently using Eclipse...

    I just need to open a word document that I have already dragged into my project file.

    I ave used te code before but can't seem to find it anywhere now.

    I remember you say something like Runtime.something(cmd/c Help.doc) or something similar, any advice?

    Secondly I want to update a table. I have like a username, password....

    but i want to update 2 things. The code I am using is as follows...


    public void updateTable2(String update) throws SQLException{

    Statement st = c.createStatement();
    st.executeUpdate(update);
    st.close();
    }

    updateTable2("UPDATE Clients SET Purchases = purchases + 1, SET Status = temp WHERE User = UserName");

    I have checked all the field name and they all right but I get this error...

    "
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unkn own Source)
    at Buy.updateTable2(Buy.java:201)
    at Buy.Order(Buy.java:361)
    at Main$2.actionPerformed(Main.java:111)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    actionPerformed()
    "

    PLz help thanks :)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    For the second part, as error message pointed your query is may be wrong. Best way is test the query on sql query wizard ans fix it.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    For the first part, to run a doc file use the following.

    Java Code:
    Runtime.getRuntime().exec(new String[]{"cmd", "/C", "start", "\"\"", your_doc_file_path});

  4. #4
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    OK how do I use the query on sql query wizard ?

    Just one last question, I am priting everything with a listModel.addElement, is the a way I can clear all the riting

  5. #5
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    Thanks A Lot :)

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  7. #7
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    Nope its fina do not want to clear it anymore.

    Is there anything wrong with my Update statement or why does it not work ?

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  9. #9
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    I am not quite sure how to test it. I tried using that SQL think in access but that only has criteria so it did not really help

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    The SET keyword should appear only once.
    Java Code:
    updateTable2("UPDATE Clients SET Purchases = purchases + 1, Status = temp WHERE User = UserName");
    Also ensure that temp is a variable of the appropriate type for the field Status, and is in scope.

    db

  11. #11
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    Yeah Status is a string...

    Now i get this error

    "
    java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.execute(Unknown Source)
    at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(Unkn own Source)
    at Buy.updateTable2(Buy.java:203)
    at Buy.Order(Buy.java:385)
    at Main$2.actionPerformed(Main.java:111)
    at javax.swing.AbstractButton.fireActionPerformed(Unk nown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed (Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseRe leased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent( Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(U nknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unkno wn Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
    actionPerformed()
    "

    TO few parameters ???

    If this keeps failing I could always delete the whole record and insert a new one but I guess that is not elegant hey

  12. #12
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    Searching the net suggests that the error is caused by a malformed SQL statement. Purchases = purchases + 1 looks suspect, but I can't be sure without knowing more about your setup.

    Check out this old posting on the Sun forum.
    forums[dot]sun[dot]com[slash]thread[dot]jspa?messageID=3993742
    quote:
    The error message from the Access driver is totally misleading, it's effectively garbage; it really just means that there is something wrong with your SQL statement.

    You get that message in all sorts of different ways, among them that the tables or column names don't actually exist.
    unquote

    Sorry, can't post a link because I don't have enough postings yet :)

  13. #13
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    Thanks man still stuck

    I changed purchases to purchases = purchases + 1 outside the SQL statement and still no luck

    I have looked on the web and my code seems to be fine but still teh same error

  14. #14
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    Runtime.getRuntime().exec(new String[]{"cmd", "/C", "start", "\"\""C:\Documents and Settings\L-Dog\My Documents\Lourens Project\UD.doc});

    and

    Runtime.getRuntime().exec(new String[]{"cmd", "/C", "start", "\"\"" /Lourens Project/UD.doc});

    Doesnt seem to work ?

  15. #15
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,423
    Rep Power
    25

    Default

    Doesnt seem to work ?
    Use the Process class and retrieve the STD and ERR output and print it to see what is happening.
    Java Code:
               Process proc = Runtime.getRuntime().exec(<command>);
    
                System.out.println(">*>*>Getting reader");
                BufferedReader br = new BufferedReader(
                                new InputStreamReader(proc.getInputStream()));
    
                System.out.println(">*>*>*>STD output follows:");
                // Read and display the output
                while((str = br.readLine()) != null) {
                    System.out.println(str);
                }
    
                System.out.println(">*>*>*>End of STD output\n>>>>>>>> Error output follows:");
                br.close();
                br = new BufferedReader(
                                new InputStreamReader(proc.getErrorStream()));
                // Read and display the output
                while((str = br.readLine()) != null) {
                    System.out.println(str);
                }
                br.close();
                System.out.println(">>>>>>>> End of error output <<<<<<<<");

  16. #16
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    I changed purchases to purchases = purchases + 1 outside the SQL statement and still no luck
    Uh-oh. It's beginning to look like your SQL should really be
    Java Code:
    "UPDATE Clients SET Purchases = " + purchases + ", Status = '" + temp + "' WHERE User = '" + UserName + "'"
    db
    Last edited by DarrylBurke; 09-28-2008 at 08:04 PM. Reason: typos, typos

  17. #17
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    OK thanks a lot guys. Plz post your real names so I can put them in the Acknowledgments that way they I don't get 0 and you feel good ;)

  18. #18
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

    Default

    It works now just the Status doenst update fills it with a blank ;(

  19. #19
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,242
    Rep Power
    19

    Default

    The only name I have is my real name and it's right there in my username. :D

  20. #20
    L-dog is offline Member
    Join Date
    Sep 2008
    Posts
    12
    Rep Power
    0

Page 1 of 2 12 LastLast

Similar Threads

  1. array problems need your help ASAP!
    By notherand in forum New To Java
    Replies: 1
    Last Post: 06-29-2008, 08:59 PM

Posting Permissions

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