Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cityout2oParadoteo;
- import java.sql.*;
- import java.util.List;
- import java.util.ArrayList;
- public class RestaurantDAO {
- String errorMessages = "";
- PreparedStatement stmt1 = null;
- PreparedStatement stmt2 = null;
- String sql1 = "select * from Restaurant where id_cat=? and id_area=?";
- String sql2 = "select * from Restaurant where id_res=?";
- ResultSet rs1 = null;
- ResultSet rs2 = null;
- List<Restaurant> restaurants = new ArrayList<Restaurant>();
- public static void main (String[] args) {
- RestaurantDAO rd = new RestaurantDAO();
- try {
- Restaurant restaurant = rd.getRestaurantInfoById(1);
- } catch (Exception e) {
- System.out.println("lol");
- }
- }
- /**
- * Default constructor
- */
- public RestaurantDAO() { }
- public List<Restaurant> getRestaurantsByChose(int catid, int areaid) throws Exception {
- Connection con = null;
- CityoutDB db = new CityoutDB();
- try {
- db.open();
- con = db.getConnection();
- stmt1 = con.prepareStatement(sql1);
- stmt1.setInt(1,catid);
- stmt1.setInt(2,areaid);
- rs1 = stmt1.executeQuery();
- if (rs1.next() == false) {
- errorMessages = "Den iparxoun kataxorimena katastimata tis epilogis sas";
- throw new SQLException(errorMessages);
- }
- rs1.previous();
- while(rs1.next()) {
- Restaurant restaurant = new Restaurant(rs1.getInt("id_res"), rs1.getString("name_res"),rs1.getString("address"),rs1.getInt("phone_res"),rs1.getString("photo_url"),rs1.getString("map_res"),rs1.getInt("id_cat"),rs1.getInt("id_area"));
- restaurants.add(restaurant);
- }
- rs1.close();
- stmt1.close();
- con.close();
- return restaurants;
- }catch (Exception e) {
- throw new Exception( e.getMessage() );
- } finally {
- try {
- db.close();
- } catch (Exception e) {
- //no need to do anything...
- }
- }
- } //End of getRestaurantsByChose
- public Restaurant getRestaurantInfoById(int idres) throws Exception {
- System.out.println("lrr");
- Connection con = null;
- CityoutDB db = new CityoutDB();
- Restaurant restaurant = null;
- try {
- db.open();
- con = db.getConnection();
- System.out.println("lrr");
- stmt2 = con.prepareStatement(sql2);System.out.println("lrr");
- stmt2.setInt(1,idres);System.out.println("lrr");
- rs2 = stmt2.executeQuery();System.out.println("lrr");
- while(rs2.next()) { System.out.println("ola kala");
- restaurant = new Restaurant(rs2.getInt("id_res"), rs2.getString("name_res"),rs2.getString("address"),rs2.getInt("phone_res"),rs2.getString("photo_url"),rs2.getString("map_res"),rs2.getInt("id_cat"),rs2.getInt("id_area"));
- System.out.println("ola kala");
- }
- rs2.close();
- stmt2.close();
- con.close();
- return restaurant;
- }catch (Exception e) {
- throw new Exception( e.getMessage() );
- } finally {
- try {
- db.close();
- } catch (Exception e) {
- //no need to do anything...
- }
- }
- } //End of getRestaurantsByChose
- } //End of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement