Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.curistec.tpbdddao;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.Properties;
- public class RectangleDAO {
- Connection conn = null;
- Statement statement;
- ResultSet resultSet;
- public RectangleDAO() throws FileNotFoundException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
- Properties conf = new Properties();
- conf.load(new FileInputStream("conf.properties"));
- String driver = conf.getProperty("driverjdbc");
- String url = conf.getProperty("url");
- String database = conf.getProperty("database");
- String user= conf.getProperty("user");
- String password= conf.getProperty("password");
- Class.forName(driver).newInstance();
- conn =DriverManager.getConnection(url+database,user,password);
- statement = conn.createStatement();
- }
- public Rectangle getRectangle(int id) throws SQLException{
- int longueur,largeur;
- String sql = "SELECT * FROM rectangles WHERE id = "+id;
- resultSet = statement.executeQuery(sql);
- resultSet.next();
- id = resultSet.getInt("ID");
- longueur= resultSet.getInt("longueur");
- largeur= resultSet.getInt("largeur");
- return new Rectangle(id,longueur,largeur);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement