
Sir i want to searching through name and id in java. and i want to show all the record(like father`s name, date of joining, maid add and mobile no. etc) of particular employee by choosing id and name

import java.sql.*;
import java.util.*;
class RetrieveData
{
public static void main(String[] args) throws Exception
{
Scanner input=new Scanner(System.in);
System.out.print("Enter id: ");
int id=input.nextInt();
System.out.print("Enter Name: ");
String name=input.next();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from data where id="+id+" and name='"+name+"'");
if(rs.next()){
String fname=rs.getString("fatherName");
String date=rs.getString("dateOfJoining");
String address=rs.getString("address");
String mobile=rs.getString("mobile");
System.out.println("Father's Name: "+fname);
System.out.println("Date of joining: "+date);
System.out.println("Address: "+address);
System.out.println("Mobile No: "+mobile);
}
}
}
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.