package dbj.jdbc; import java.io.*; import java.sql.*; import java.util.Properties; public class Utils { public static String readString (String prompt) { String result = null; System.out.print (prompt); try { BufferedReader in = new BufferedReader (new InputStreamReader (System.in)); result = in.readLine (); } catch (IOException exc) { result = null; } return result; } public static int readInt (String prompt) { int result = 0; System.out.print (prompt); try { BufferedReader in = new BufferedReader (new InputStreamReader (System.in)); result = Integer.parseInt (in.readLine ()); } catch (Exception exc) { result = 0; } return result; } public static Connection getConnection () throws SQLException { Connection con = null; Properties properties = new Properties (); try { properties.load (new FileInputStream ("dbj.properties")); Class.forName (properties.getProperty ("jdbc.driver")); } catch (IOException exc) { System.out.println ("Property file not found !"); return null; } catch (ClassNotFoundException exc) { System.out.println ("Driver class not found !"); return null; } String url = properties.getProperty ("jdbc.url"); con = DriverManager.getConnection (url, properties.getProperty ("jdbc.user"), properties.getProperty ("jdbc.password")); return con; } }