Java data access

Page 76

Chapter 5: Building JDBC Statements //Ignore Oracle DROP table error. if(se.getErrorCode()==942) { String msg = se.getMessage(); System.out.println("Error dropping Employees table: " + }

msg);

} //Build the Location table if(stmt.executeUpdate(locationSql)==0) System.out.println("Location table created..."); try { String dropSql = "DROP TABLE Employees CASCADE CONSTRAINTS"; stmt.executeUpdate(dropSql); } catch(SQLException se) { //Ignore Oracle DROP table error. if(se.getErrorCode()==942) { String msg = se.getMessage(); System.out.println("Error dropping Employees table: " + } } //Build the Employees table if (stmt.executeUpdate(employeeSql)==0) System.out.println("Employees table created..."); } // end of createTables method public static void insertData()throws SQLException { //Load Location table with data stmt.executeUpdate("INSERT INTO " + "Location VALUES(100,’Knoxville’)"); stmt.executeUpdate("INSERT INTO " + "Location VALUES(200,’Atlanta’)"); stmt.executeUpdate("INSERT INTO " + "Location VALUES(300,’New York’)"); stmt.executeUpdate("INSERT INTO " + "Location VALUES(400,’L.A.’)"); stmt.executeUpdate("INSERT INTO " + "Location VALUES(500,’Tulsa’)"); //Load Employee table with data stmt.executeUpdate("INSERT INTO Employees VALUES(111111111," +"’Todd’,’5000’,{d ‘1995−09−16’},100)"); stmt.executeUpdate("INSERT INTO Employees VALUES(419876541," +"’Larry’,’1500’,{d ‘2001−03−05’},200)"); stmt.executeUpdate("INSERT INTO Employees VALUES(312654987," +"’Lori’,’2000.95’,{d ‘1999−01−11’},300)"); stmt.executeUpdate("INSERT INTO Employees VALUES(123456789," +"’Jimmy’,’3080’,{d ‘1997−09−07’},400)");

64

msg);


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.