package oracledemo;
import java.sql.*;
import java.util.Scanner;
import javax.sql.*;
public class moxie0926 {
/ **
* @param args
* /
public static void main (String [] args) {
Scanner Scanner new new INPUT = (the System.in);
of System.out.print ( "Please enter the department number:");
int = INPUT deptnos .nextInt ();
System.out.print ( "Please enter a department name:");
String dnames = input.next ();
System.out.print ( "Please enter the city department:");
String = LOCS the iNPUT. Next ();
the try {
// load the driver. 1.
the Class.forName ( "oracle.jdbc.OracleDriver");
// 2 establish a connection object.
connection the DriverManager.getConnection = CON ( "JDBC: Oracle: Thin: @localhost: 1521 : orcl "," scott "," 123456 ");
. 3 // create a command statement object
PreparedStatement pstmt = con.prepareStatement (" INSERT INTO the dept values (,,???) ");
// 4.Subject to the command parameter value of the SQL statement to add
pstmt.setInt (1, deptnos);
pstmt.setString (2, dnames);
pstmt.setString (. 3, LOCS);
.. 5 // Create an object to execute the statement
int pstmt.executeUpdate PS = ();
IF (PS> 0) {
System.out.println ( "Add success ");
} the else {
System.out.println (" add failed ");
}
// close objects
pstmt.close ();
con.close ();
} the catch (a ClassNotFoundException E) {
e.printStackTrace ();
} the catch (SQLException E) {
e.printStackTrace ();
}
}
}