File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes I can select, insert, update but not delete.. please help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "I can select, insert, update but not delete.. please help" Watch "I can select, insert, update but not delete.. please help" New topic
Author

I can select, insert, update but not delete.. please help

Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Hi everybody,

My problem is that I can Isnert, Update, and Select from my databse but canot delete. I get always this Exception when I try to delete:


This is the code when the query is submitted:

And this is my DatabaseConnection class:


Could someone please hlep me???
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
See the exception itself tells you where is the error is.
Whats the SQL you are using to delete from a table ?


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

Romaysa,

There are many system.out.println in your program.
can you tell us which one is last system.out printed to ccnsole.

and what is the delete query formed by your program.

thanks


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
This is my Sql Query:
String deleteQuery= "DELETE "+
"FROM irn_gebruiker "+
"WHERE gebruikersnaam ='" +deletedGeb+"';";

This is the printed query in my consoll:
===== De gebruikers is succesvol verwijderd: Test 22 DELETE FROM irn_gebruiker WHERE gebruikersnaam ='Test 22';

Test 22 is the selected User which I want to delete.
[ January 07, 2005: Message edited by: Azz Romaysa ]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Azz Romaysa:
This is my Sql Query:
String deleteQuery= "DELETE "+
"FROM irn_gebruiker "+
"WHERE gebruikersnaam ='" +deletedGeb+"';";


Is that ";" really needed.
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
i think the ; at the end of the statement is only needed in the mysql console but not in JDBC. try without.

pascal
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
It stills give the same Exception:

Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Hi Friend,

Do this , write the Delete SQl statement and execute it manually , in a tool like TOAD or SQL console.
If it works format the same delete statement in java code , but without ";"
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

I think I found the errror

Check the line

ResultSet rs = conn.getInformation("deleteQuery", 0);


this line should be written as

ResultSet rs = conn.getInformation(deleteQuery, 0);

instead of passing delete query variable you are passing a string as "deleteQuery" in getInformation method.

please verify same and revert

thanks

Shailesh
[ January 07, 2005: Message edited by: Shailesh Chandra ]
Azz Romaysa
Ranch Hand

Joined: Dec 08, 2004
Posts: 66
Shailesh,

I don't know how should I thank you....
Yes that was the fout... I was blind that I couldn't see it.
It works now great.

Thank you very very much.
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Shailesh Gud work well done .
Where r u from ?
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

We all learn by mistakes

cheers Shailesh
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

thanks srini....

I had sent you a personal messsage about me, by the way I am from Delhi

Shailesh
[ January 07, 2005: Message edited by: Shailesh Chandra ]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Originally posted by Shailesh Chandra:
thanks srini....

I had sent you a personal messsage about me, by the way I am from Delhi

Shailesh

[ January 07, 2005: Message edited by: Shailesh Chandra ]


Shailesh Do you remember couple of days back i also made a silly, bloody ( sorry for using this word ) mistake , you found that out !!
This happens ... We have to correct it.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1076

yes I remember.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: I can select, insert, update but not delete.. please help
 
Similar Threads
Error when deleting a row in the Database ...
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException
error in update query
Update query is wrong?
Getting EXception