Write a java program to insert a record in dept database by accepting the data from keyboard at runtime using dynamic queries?
import java.sql.*;
import java.io.*;
class InsertRecRun {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("DRIVERS LOADED...");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:
BudDinu "," scott "," tiger ");
System.out.println("CONNECTION OBTAINED...");
PreparedStatement ps = con.prepareStatement("insert into dept values
(?,?,?)");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER DEPARTMENT NUMBER : ");
String s1 = dis.readLine();
int dno = Integer.parseInt(s1);
System.out.println("ENTER DEPARTMENT NAME : ");
String dname = dis.readLine();
System.out.println("ENTER LOCATION NAME : ");
String loc = dis.readLine(); ps.setInt(1, dno);
ps.setString(2, dname);
ps.setString(3, loc);
int i = ps.executeUpdate();
System.out.println(i + "ROW(s) INSERTED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // InsertRecRun
import java.sql.*;
import java.io.*;
class InsertRecRun {
public static void main(String[] args) {
try {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
System.out.println("DRIVERS LOADED...");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:
BudDinu "," scott "," tiger ");
System.out.println("CONNECTION OBTAINED...");
PreparedStatement ps = con.prepareStatement("insert into dept values
(?,?,?)");
DataInputStream dis = new DataInputStream(System.in);
System.out.println("ENTER DEPARTMENT NUMBER : ");
String s1 = dis.readLine();
int dno = Integer.parseInt(s1);
System.out.println("ENTER DEPARTMENT NAME : ");
String dname = dis.readLine();
System.out.println("ENTER LOCATION NAME : ");
String loc = dis.readLine(); ps.setInt(1, dno);
ps.setString(2, dname);
ps.setString(3, loc);
int i = ps.executeUpdate();
System.out.println(i + "ROW(s) INSERTED...");
con.close();
} catch (Exception e) {
e.printStackTrace();
}
} // main
} // InsertRecRun
No comments:
Post a Comment