Re: problem
Martin MC Brown <[email protected]> Thu, 8 Mar 2007 11:32:28 +0000
| Newsgroups | gmane.comp.db.mysql.java |
|---|---|
| Message-ID | <[email protected]> |
Hi,
> I have got a problem.
> how to write a code in jdbc with mysql ,for insertion,search for
> variable.
> i.e ehen i write somthing like
> String dep1=d.getText();
> smnt.executequery("select e.name ,e.salary"+" "+"from Emp e"+ " "
> +"where e.dept=" dep1);
>
> I get an error syntax error,similar is case of insertion .
You will get an error for because you have not quoted the text string
you are looking matching against. I'm also not clear why you use 'Emp
e' for the table name. In effect the query you have written will read
like this:
select e.name, e.salary from Emp e where e.dept = string
When it should read:
select e.name,e.salary from e where e.dept = 'string'
Others have provided suitable solutions, but to change your original:
smnt.executequery("select e.name ,e.salary from e where e.dept='" +
dep1 + "'");
MC
--
Martin MC Brown, Technical Writer
MySQL AB, http://www.mysql.com
Skype: mcmcslp
--
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe: http://lists.mysql.com/[email protected]