Write a java program to retrieve the records from a specified database by accepting input from keyboard?
import java.sql.*;
import java.io.*;
class SelectDataRun {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
PreparedStatement ps = con.prepareStatement("select * from dept where deptno");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER DEPARTMENT NUMBER : ");
String s1 = dis.readLine();
int dno = Integer.parseInt(s1);
ps.setInt(1, dno);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.print(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // SelectDataRun
import java.sql.*;
import java.io.*;
class SelectDataRun {
public static void main(String[] args) {
try {
Class.forName("Sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("DRIVERS LOADED...");
Connection con = DriverManager.getConnection("jdbc:odbc:oradsn", "scott", "tiger");
System.out.println("CONNECTION ESTABLISHED...");
PreparedStatement ps = con.prepareStatement("select * from dept where deptno");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER DEPARTMENT NUMBER : ");
String s1 = dis.readLine();
int dno = Integer.parseInt(s1);
ps.setInt(1, dno);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
System.out.print(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // SelectDataRun
No comments:
Post a Comment