Re: problem

Thomas Lundström <[email protected]> Thu, 08 Mar 2007 09:30:37 +0100
Newsgroups gmane.comp.db.mysql.java
Message-ID <[email protected]>
Hi Soni!

I don't know how far from your actual code the snippet you've provided 
is but your execute query should probably look something like this:

// Init driver and setup connection
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = 
DriverManager.getConnection("jdbc:mysql://localhost/test","test","test123");

// Execute query
String dep1=d.getText();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select e.name, e.salary from Emp e 
where e.dept = '" + dep1 + "'");
while(rs.next()) {
String name = rs.getString(1);
float salary = rs.getFloat(2);
System.out.println("Name " + name + " has salary " + salary);
}
rs.close();
stmt.close();
con.close();

Some googling also gave links like: 
http://www.kitebird.com/articles/jdbc.html

Regards

Thomas Lundström

soni avbnb wrote:
> 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 .
>
>
> please help..
>
>  				
> ---------------------------------
>  Here’s a new way to find what you're looking for - Yahoo! Answers 
>   

-- 
MySQL Java Mailing List
For list archives: http://lists.mysql.com/java
To unsubscribe:    http://lists.mysql.com/[email protected]