I wrote this java program to fetch data from database table.I solved all the errors and exceptions regarding the path and environment variables but at the end the values present in my mysql database table are not getting displayed.
Java code:
import java.sql.*;
class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con=DriverManager.getConnection(
"jdbc:mysql://localhost:3306/sonoo","root","Password@123");
//here sonoo is database name, root is username and password
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getInt(3));
con.close();
}catch(Exception e){ System.out.println(e);}
}
}
Mysql table:-
create database sonoo;
use sonoo;
create table emp(id int,name varchar(40),age int);
I am expecting this code to fetch records from my database table