dbTalk Databases Forums  

new to Mysql probably a simple answer !!!

mailing.database.mysql mailing.database.mysql


Discuss new to Mysql probably a simple answer !!! in the mailing.database.mysql forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
vivienne wykes
 
Posts: n/a

Default new to Mysql probably a simple answer !!! - 07-22-2004 , 02:20 PM






Hi All,

I have a JSP / mysql problem.

I would like a (JSP) user selected variable to be passed into an sql
statement.

My code is passing the variable which is item_Id to a java bean called "
thisBean" which passes in the item_Id variable chosen by the user.

My problem is that I cannot get my sql statement to recognise the variable.

Can I pass in a variable to a sql statement that will delete a row from my
table which is called items.

If I can how is this acheived ?

My code is below.

Thanks very much

statement.executeUpdate("DELETE FROM items WHERE item_Id = '" +item_Id +
"'");

Complete bean code :


public class ScrubWedding
{
//String weddingid ;
java.sql.PreparedStatement statement;
java.sql.Connection connection;
String item_Id;

public ScrubWedding(){ }

public void removeWedding(String item_Id)
{

try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstan ce();
System.out.println ("after Class.forname");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:mysql://localhost/shop");
java.sql.Statement statement = connection.createStatement();

statement.executeUpdate("DELETE FROM items WHERE item_Id = '" +item_Id
+ "'"); *********** The line I am having problems with !!!!

System.out.println ("after executeUpdate");

if (statement != null )
statement.close();

if ( connection != null )
connection.close();


}
catch(Exception e)
{
e.printStackTrace(System.err) ;
}





}
}




Reply With Quote
  #2  
Old   
Aggro
 
Posts: n/a

Default Re: new to Mysql probably a simple answer !!! - 07-22-2004 , 04:22 PM






vivienne wykes wrote:

Quote:
statement.executeUpdate("DELETE FROM items WHERE item_Id = '" +item_Id +
"'");
Make a string from your query, echo or print it somewhere before using
it to make sure variables contain the data you expect them to contain.
(Most common reason for errors.)

It the query seems to be correct. Copy-paste it to mysql-console program
and try to execute it from there. If it doesn't work from there, there
is something wrong with the query. If it works, there is something wrong
with the application from which you are sending the query. In that case
try to catch errors and print out the error messages you might receive.
They might give a hint about what is wrong.


Reply With Quote
  #3  
Old   
vivienne wykes
 
Posts: n/a

Default Re: new to Mysql probably a simple answer !!! - 07-22-2004 , 07:54 PM



Thanks for that,

I was passing in " item_Id" in iverted commas so I was trying to remove the
string not the variable.

regards.

"Aggro" <spammerdream (AT) yahoo (DOT) com> wrote

Quote:
vivienne wykes wrote:

statement.executeUpdate("DELETE FROM items WHERE item_Id = '" +item_Id
+
"'");

Make a string from your query, echo or print it somewhere before using
it to make sure variables contain the data you expect them to contain.
(Most common reason for errors.)

It the query seems to be correct. Copy-paste it to mysql-console program
and try to execute it from there. If it doesn't work from there, there
is something wrong with the query. If it works, there is something wrong
with the application from which you are sending the query. In that case
try to catch errors and print out the error messages you might receive.
They might give a hint about what is wrong.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.