Results 1 to 20 of 23
Thread: Need Java Help ASAP
- 09-28-2008, 11:01 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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 :)
- 09-28-2008, 11:05 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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.
- 09-28-2008, 11:08 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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});
- 09-28-2008, 11:09 AM #4
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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
- 09-28-2008, 11:09 AM #5
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
Thanks A Lot :)
- 09-28-2008, 11:13 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
What you are looking to clear? I'm not clear what you are asking.
- 09-28-2008, 11:21 AM #7
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
Nope its fina do not want to clear it anymore.
Is there anything wrong with my Update statement or why does it not work ?
- 09-28-2008, 11:48 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Did you test it on sql query wizard?
- 09-28-2008, 12:03 PM #9
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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
- 09-28-2008, 12:44 PM #10
The SET keyword should appear only once.
Also ensure that temp is a variable of the appropriate type for the field Status, and is in scope.Java Code:updateTable2("UPDATE Clients SET Purchases = purchases + 1, Status = temp WHERE User = UserName");
db
- 09-28-2008, 01:04 PM #11
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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
- 09-28-2008, 02:02 PM #12
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 :)
- 09-28-2008, 03:32 PM #13
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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
- 09-28-2008, 04:29 PM #14
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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 ?
- 09-28-2008, 04:37 PM #15
Use the Process class and retrieve the STD and ERR output and print it to see what is happening.Doesnt seem to work ?
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 <<<<<<<<");
- 09-28-2008, 08:03 PM #16
Uh-oh. It's beginning to look like your SQL should really beI changed purchases to purchases = purchases + 1 outside the SQL statement and still no luck
dbJava Code:"UPDATE Clients SET Purchases = " + purchases + ", Status = '" + temp + "' WHERE User = '" + UserName + "'"
Last edited by DarrylBurke; 09-28-2008 at 08:04 PM. Reason: typos, typos
- 09-28-2008, 08:36 PM #17
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
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 ;)
- 09-28-2008, 08:56 PM #18
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
It works now just the Status doenst update fills it with a blank ;(
- 09-28-2008, 08:58 PM #19
The only name I have is my real name and it's right there in my username. :D
- 09-28-2008, 09:03 PM #20
Member
- Join Date
- Sep 2008
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
array problems need your help ASAP!
By notherand in forum New To JavaReplies: 1Last Post: 06-29-2008, 08:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks