Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hw3;
- import java.sql.*;
- import java.util.Scanner;
- public class GP3_Problem2_Group29 {
- public static void main(String[] args) {
- //load a database driver
- try {
- Class.forName("oracle.jdbc.OracleDriver");
- }catch(Exception x){
- System.out.println("Unable to load the driver class!");
- }
- System.out.println("loading database connection . . .");
- //create an oracle JDBC connection
- try{
- Connection dbConnection=DriverManager.getConnection("jdbc:oracle:thin:@//oracle.cs.ou.edu:1521/pdborcl.cs.ou.edu","bask4499","LJnd8Dz9");
- //create an oracle statement object
- Statement stmt = dbConnection.createStatement();
- System.out.println("Please select an option by typing an integer");
- Scanner sc = new Scanner(System.in);
- int i = sc.nextInt();
- while(i!=4){
- switch(i){
- case 1:
- //OPTION 1
- //Create new customer record
- //with user entered cid, cname, level
- //and number_of_orders = avg num orders for current entries with same level
- String cid,cname,level;
- int number_of_orders = 0;
- System.out.println("cid? ");
- cid = sc.next();
- System.out.println("cname? ");
- cname = sc.next();
- System.out.println("level? ");
- level = sc.next();
- //get the avg num orders for the given level
- CallableStatement cs;
- cs = dbConnection.prepareCall("{call GETAVGNUMORDERSFOR(?,?)}");
- //if parameter is an IN parameter, use cs.set[parameterType](index,value)
- cs.setString(1, level);
- //if parameter is an OUT parameter use cs.registerOutParameter,
- //then cs.get[parameterType] after calling cs.execute
- cs.registerOutParameter(2, Types.NUMERIC);
- cs.execute();
- number_of_orders = cs.getInt(2);
- cs = dbConnection.prepareCall("{call NEWCUSTOMER(?,?,?,?)}");
- cs.setInt(1, Integer.valueOf(cid));
- cs.setString(2,cname);
- cs.setInt(3, number_of_orders);
- cs.setString(4, level);
- cs.execute();
- System.out.println("Successfully added new customer record");
- break;
- case 2:
- //TODO: put option 2 code here
- break;
- case 3:
- //display complete information of all customers and translators
- break;
- default:
- System.out.print("Invalid option, please enter an option from 1 to 4");
- break;
- }
- System.out.println("Please select an option by typing an integer");
- i = sc.nextInt();
- }
- System.out.println("Exiting");
- dbConnection.close();
- sc.close();
- }catch( SQLException x ){
- System.out.println("Couldn’t get connection!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement