Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package connection;
- import java.sql.*;
- public class DataBaseConnection {
- private Connection connection;
- private Statement statment;
- private ResultSet resultSet;
- private String sql;
- public DataBaseConnection() {
- };
- public boolean IsConnected() {
- String driver = "com.mysql.jdbc.Driver";
- String url = "jdbc:mysql://localhost/employes";
- String username = "root";
- String password = "";
- try {
- Class.forName(driver).newInstance();
- } catch (InstantiationException e) {
- e.printStackTrace();
- return false;
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- try {
- connection = DriverManager.getConnection(url, username, password);
- System.out.println("Connected");
- } catch (SQLException e1) {
- e1.printStackTrace();
- return false;
- }
- return true;
- }
- public boolean executerUpdate(String sql) {
- try {
- statment = connection.createStatement();
- statment.executeUpdate(sql);
- } catch (SQLException e) {
- e.printStackTrace();
- return false;
- }
- return true;
- }
- public boolean executerRequete(String sql) {
- try {
- statment = connection.createStatement();
- setResultSet(statment.executeQuery(sql));
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return false;
- }
- return true;
- }
- /**
- * @param resultSet
- * the resultSet to set
- */
- public void setResultSet(ResultSet resultSet) {
- this.resultSet = resultSet;
- }
- /**
- * @return the resultSet
- */
- public ResultSet getResultSet() {
- return resultSet;
- }
- /**
- * @param sql
- * the sql to set
- */
- public void setSql(String sql) {
- this.sql = sql;
- }
- /**
- * @return the sql
- */
- public String getSql() {
- return sql;
- }
- }
Add Comment
Please, Sign In to add comment