Click Here to Know the Steps to Connect database in Linux Environment System
import java.io.*;
import java.sql.*;
class jdbc3
{
public static void main(String args[])throws SQLException
{
int reg;
String name,address;
try
{
DataInputStream in=new DataInputStream(System.in);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/student","root","password");
Statement stm=con.createStatement();
System.out.println("Reg_no Name Address");
System.out.println("-------------------------------");
String s1="select * from student";
ResultSet rs=stm.executeQuery(s1);
while(rs.next())
{
reg=rs.getInt("reg");
name=rs.getString("name");
address=rs.getString("address");
System.out.println(reg + "\t" + name + "\t" + address + "\t");
}
stm.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Click Here to Know the Steps to Connect database in Linux Environment Systemimport java.sql.*;
class jdbc3
{
public static void main(String args[])throws SQLException
{
int reg;
String name,address;
try
{
DataInputStream in=new DataInputStream(System.in);
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con=DriverManager.getConnection("jdbc:mysql://localhost/student","root","password");
Statement stm=con.createStatement();
System.out.println("Reg_no Name Address");
System.out.println("-------------------------------");
String s1="select * from student";
ResultSet rs=stm.executeQuery(s1);
while(rs.next())
{
reg=rs.getInt("reg");
name=rs.getString("name");
address=rs.getString("address");
System.out.println(reg + "\t" + name + "\t" + address + "\t");
}
stm.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}