import java.sql.*; import java.util.Properties; class myDatabase { private Connection conn; public void open() { Properties props = new Properties(); props.put("user", "cb97mre"); props.put("password", "cb97mre"); props.put("server", ""); try { java.sql.Driver d = (java.sql.Driver)Class.forName("weblogic.jdbc.oci.Driver").newInstance(); DriverManager.setLogStream(java.lang.System.out); conn = d.connect("jdbc:weblogic:oracle", props); //Class.forName("weblogic.jdbc.oci.Driver"); //conn = DriverManager.getConnection("jdbc:weblogic:oracle:kayak", "sangeeta", "sangeeta"); //Driver d = new weblogic.jdbc.oci.Driver(); //conn = new weblogic.jdbc.oci.Driver().connect("jdbc:weblogic:oracle", props); System.err.println("Connected to database"); } catch (Exception e) { System.err.println("Error connection: " + e);} } public void getCarInfo(StringBuffer id, CarData car) { String query = "select * from bmw_car_table where car_id like '%"+id+"%'"; System.out.println(id); try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); if (rs.next()) { System.out.println("HOLA!!!!"); car.Id.setLength(0); car.Id.append(rs.getString("car_id")); car.Img.setLength(0); car.Img.append(rs.getString("car_image")); car.Name.setLength(0); car.Name.append(rs.getString("car_name")); car.Engine.setLength(0); car.Engine.append(rs.getString("car_engine")); car.Size.setLength(0); car.Size.append(rs.getString("car_size")); car.Price.setLength(0); car.Price.append(rs.getString("car_price")); car.Comments.setLength(0); car.Comments.append(rs.getString("car_comments")); } } catch (Exception e) { System.err.println("Error in dbase"); e.printStackTrace(); } } public void find(String word, StringBuffer s1, StringBuffer s2, StringBuffer s3, StringBuffer s4, StringBuffer s5, StringBuffer s6, StringBuffer s7) { String car_name = "M3 Coupe"; String low = "$30,000"; String up = "$35,999"; String query1 = "select * from bmw_car_table where car_name like '%"+car_name+"%'"; String query2 = "select * from bmw_car_table where car_price > '"+low+ "' AND car_price < '" + up + "'"; try { System.out.println("name passed = " + word); Statement stmt = conn.createStatement(); //stmt.setString(1,word); ResultSet rs = stmt.executeQuery(query2); while (rs.next()){ s1.append(rs.getString("car_id")); s1.append(" - "); // s2.append("-"); s2.append(rs.getString("car_image")); /// s2.append("-"); s3.append(rs.getString("car_name")); s3.append(" - "); s4.append(rs.getString("car_engine")); s4.append(" - "); s5.append(rs.getString("car_size")); s5.append(" - "); s6.append(rs.getString("car_price")); s6.append(" - "); s7.append(rs.getString("car_comments")); s7.append(" - "); //stmt.close(); System.out.println (rs.getString("car_name")); System.out.println(rs.getString("car_image")); // return; } } catch (Exception e) { System.err.println("Error in dbase"); e.printStackTrace(); } } public int getMatchCount(String low, String high) { String query2 = "select car_id from bmw_car_table where car_price > '"+low+ "' AND car_price < '" + high + "'"; int count = 0; try { //System.out.println(query2); Statement stmt = conn.createStatement(); //stmt.setString(1,word); ResultSet rs = stmt.executeQuery(query2); while (rs.next()){ count++; // System.out.println (rs.getString("car_name")); //System.out.println(rs.getString("car_image")); // return; } } catch (Exception e) { System.err.println("Error in dbase"); e.printStackTrace(); } return count; } public void getIDList(String low, String high, StringBuffer idList[]) { // String query1 = "select car_id from bmw_car_table where car_name like '%"+car_name+"%'"; String query2 = "select car_id from bmw_car_table where car_price > '"+low+ "' AND car_price < '" + high + "'"; try { //System.out.println(query2); Statement stmt = conn.createStatement(); //stmt.setString(1,word); ResultSet rs = stmt.executeQuery(query2); int i=0; while (rs.next()){ idList[i].append(rs.getString("car_id")); i++; } } catch (Exception e) { System.err.println("Error in dbase"); e.printStackTrace(); } } public void close() { try { conn.close(); } catch (Exception e) {System.err.println("Error in closing dbase");} } }