import java.sql.*; /** * *
Title: connect class
*Description: Connect class takes care of the connection between our interface * and Oracle database.
*Copyright: Copyright (c) 2003
*Company:
*@author : CHiemi Umezawa
*@version sdk1.4.2
*/ public class connect{ private Connection conn; private Statement stmt; private ResultSet rset; private boolean connected; /** * Purpose: This is a constructor of this class that initializes all fields. * Pre: * Post: All fields are initilized. */ public connect(){ conn = null; stmt = null; rset = null; connected = false; } /** * Purpose: This method will try to make a connection to the Oracle, using the * given username and password. * @param user * @param pswd * @throws SQLException * @throws java.lang.ClassNotFoundException */ public void start(String user, String pswd) throws SQLException, ClassNotFoundException { try { String userName = user; String passwd = pswd; Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection("jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=ect-sun.ecst.csuchico.edu)(PORT=1521)))(CONNECT_DATA=(SID=ecstDB)(SERVER=DEDICATED)))", userName, passwd); stmt = conn.createStatement(); //create a table //CreateGroceryStoreData cgsd = new CreateGroceryStoreData(stmt); create(); System.out.println("DONE"); } catch (SQLException e) { System.out.println("SQLException occured. Please do this again. "); System.exit(0); } connected = true; } /** * Purpose: This method returns ResultSet obtained from a specific query. * Pre: query is correct. * Post: The ResultSet object is obtained from the given query, and is returned. * @param query * @return ResultSet */ protected ResultSet getResult(String query){ try{ rset = stmt.executeQuery(query); }catch(SQLException e){ rset = null; } return rset; } /** * Purpose: This create method creates a new table. * Pre: stmt