Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkgfilmassignment;
- //import java.io.IOException;
- //import java.sql.DriverManager;
- //import java.sql.ResultSet;
- //import java.sql.Statement;
- //import java.sql.SQLException;
- //import java.util.Scanner;
- import java.sql.*;
- import java.io.*;
- import java.util.*;
- /**
- *
- * @author B00667769
- */
- public class Film {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws SQLException, IOException {
- // the following statement loads the Oracle jdbc driver
- // make sure it is in the CLASSPATH
- try {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- } catch (ClassNotFoundException e) {
- System.out.println("Could not load the driver");
- }
- String user = "SYSTEM", pass = "Labuser1", host = "localhost", servicename;
- Scanner strInput = new Scanner(System.in);
- System.out.println("Type userid, password, hostname or ipaddress: ");
- // do {
- // System.out.println("Please enter the host url");
- // try {
- // host = KeyB.next();//allows input for user
- // verdict = true;
- // } catch (Exception ex) {
- // System.out.println(ex.getMessage());
- // verdict = false;
- // }
- // } while (verdict == false);//ensures correct format before allowing system to continue
- //
- //
- //
- // verdict = false;
- // do {
- // System.out.println("Please enter your Username");
- // try {
- // user = KeyB.next();
- // verdict = true;
- // } catch (Exception ex) {
- // System.out.println(ex.getMessage());
- // verdict = false;
- // }
- //
- // } while (verdict == false);
- //
- // verdict = false;
- // do {
- // System.out.println("Please enter your Password");
- // try {
- // pass = KeyB.next();
- // verdict = true;
- // } catch (Exception ex) {
- // System.out.println(ex.getMessage());
- // verdict = false;
- // }
- //
- // } while (verdict == false);
- servicename = "orcl";
- System.out.println(user + " " + pass + " " + host);
- //Connection conn = null;
- // userid, password and hostname are obtained from the console
- try ( //try-with-resources
- java.sql.Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@" + host + ":1521:" + servicename, user, pass))//end try
- {//start try block
- Statement state = conn.createStatement();
- /* JDBC default is to commit each SQL statement as it is sent to the database.
- Setting autocommmit=false changes the default behaviour so that transactions
- have to be committed explicity.
- */
- conn.setAutoCommit(false);
- // Creating a statement lets us issue commands against the connection.
- Statement s = conn.createStatement();
- // Creating and populating Actor table
- //s.executeUpdate("create table Actor( ActorName VARCHAR(20) PRIMARY KEY, Sex VARCHAR(6), Nationality VARCHAR(20), DOB DATE, DebutFilmTitle VARCHAR(30))");
- System.out.println("Created table Actor");
- //s.executeUpdate("insert into Actor values('George Clooney', 'Male', 'American', Date'1965-12-04','Casualty')");
- //conn.commit();
- System.out.println("Inserted some actors");
- //ResultSet result = s.executeQuery("Select * From Actor");
- // System.out.println("Results: ");
- // while (result.next()) {
- // System.out.println(result.getString(1) + " " + result.getString(2) + " " + result.getString(3) + " " + result.getString(4) + " " + result.getString(5));
- // }
- // We end the transaction and the connection.
- conn.commit();
- conn.close();
- } catch (SQLException se) {
- se.printStackTrace(System.err);
- }//catch
- }//end main
- public static String createTable(Statement state, Connection conn) throws SQLException, IOException{
- conn.setAutoCommit(false);//transactions need to be carried out explicity
- state = conn.createStatement();
- state.executeUpdate("create table ASS2_FILM( Fnum NOT NULL AUTO_INCREMENT VARCHAR(20) PRIMARY KEY, Film SYS.XMLTYPE)");
- conn.commit();
- return "Tables created";
- }//end create table
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement