
I got an error when i did the following program the prg. is to "select the name from database when the age is given for the respective name" error i got is:SQL exception please give me the solution by providing the exact coding,as soon as possible.

import java.sql.*;
class Retrieve{
public static void main(String[] args){
try{
int age=16;
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select name from student where age="+age+"");
if(rs.next()){
System.out.println("Name: "+rs.getString("name"));
}
}
catch(Exception e){
System.out.println(e);
}
}
}

ur better to use in the place of statment to prepareStatment ur get the result how it is like
String query="select name from student where age=?"; PrepareStatment ps=con.prePrepateStatment(query); ps.setInt(1,age); ResultSet rs=ps.executeQuery()
ur getting the result. why in the place of statement i am taking the preparedStatment is every time the we are executiing the program in the web application it will complie and setting the values. if u take the preparedStatment one complie and evry time the request coming the values will be seted
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.