Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package com.curistec.tpbdddao;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.sql.Connection;
  7. import java.sql.DriverManager;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.sql.Statement;
  11. import java.util.Properties;
  12.  
  13. public class RectangleDAO {
  14. Connection conn = null;
  15. Statement statement;
  16. ResultSet resultSet;
  17.  
  18. public RectangleDAO() throws FileNotFoundException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
  19. Properties conf = new Properties();
  20. conf.load(new FileInputStream("conf.properties"));
  21. String driver = conf.getProperty("driverjdbc");
  22. String url = conf.getProperty("url");
  23. String database = conf.getProperty("database");
  24. String user= conf.getProperty("user");
  25. String password= conf.getProperty("password");
  26. Class.forName(driver).newInstance();
  27. conn =DriverManager.getConnection(url+database,user,password);
  28.  
  29. statement = conn.createStatement();
  30. }
  31.  
  32. public Rectangle getRectangle(int id) throws SQLException{
  33. int longueur,largeur;
  34. String sql = "SELECT * FROM rectangles WHERE id = "+id;
  35. resultSet = statement.executeQuery(sql);
  36. resultSet.next();
  37. id = resultSet.getInt("ID");
  38. longueur= resultSet.getInt("longueur");
  39. largeur= resultSet.getInt("largeur");
  40. return new Rectangle(id,longueur,largeur);
  41.  
  42. }
  43.  
  44.  
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement