import java.sql.*;
import java.io.*;
class Search
{
public static void main(String args[])
{
Connection conn=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:nik");
Statement stmt=conn.createStatement();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter roll no u want to search");
int rno=Integer.parseInt(br.readLine());
rs=stmt.executeQuery("select * from stud where Rno="+rno);
System.out.println("success");
while(rs.next())
{
System.out.println("RollNo="+rs.getInt(1)+""+"name="+rs.getString(2)+" "+"per="+rs.getInt(3));
}
rs.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
Output:-
----------------------------------------------------------
D:\5242>javac Search.java
D:\5242>java Search
enter roll no u want to search
1
success
RollNo=1 name=rohan per=90
No comments:
Post a Comment