
import java.sql.*;
class RetrieveData
{
public static void main(String[] args) throws Exception
{
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");
while(rs.next()){
String fname=rs.getString("fatherName");
String date=rs.getString("dateOfJoining");
String address=rs.getString("address");
String contact=rs.getString("contactNo");
System.out.println("Father's Name: "+fname);
System.out.println("Date of joining: "+date);
System.out.println("Address: "+address);
System.out.println("Contact No: "+contact);
}
}
}
For more information, visit the following link:
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.