Click Here to Know the Steps to Connect database in Linux Environment System
import java.io.*;
import java.sql.*;
class jdbc4
{
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();
String s2="select * from student;";
ResultSet rs1=stm.executeQuery(s2);
System.out.println("Reg_no Name Address");
System.out.println("---------------------------------");
while(rs1.next())
{
reg=rs1.getInt("reg");
name=rs1.getString("name");
address=rs1.getString("address");
System.out.println(reg + "\t" + name + "\t" + address + "\t");
}
System.out.println("Enter the regno");
reg=Integer.parseInt(in.readLine());
System.out.println("Reg_no Name Address");
System.out.println("---------------------------------");
String s1="select * from student where reg=" + reg + ";";
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 jdbc4
{
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();
String s2="select * from student;";
ResultSet rs1=stm.executeQuery(s2);
System.out.println("Reg_no Name Address");
System.out.println("---------------------------------");
while(rs1.next())
{
reg=rs1.getInt("reg");
name=rs1.getString("name");
address=rs1.getString("address");
System.out.println(reg + "\t" + name + "\t" + address + "\t");
}
System.out.println("Enter the regno");
reg=Integer.parseInt(in.readLine());
System.out.println("Reg_no Name Address");
System.out.println("---------------------------------");
String s1="select * from student where reg=" + reg + ";";
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();
}
}
}