Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package model;
- // Import all necessary packages
- import java.sql.*;
- /**
- * Class that implements data base and all operations that can be made with it.
- * @author kuba
- */
- public class DataBase
- {
- public DataBase()
- {
- try
- {
- Class.forName("oracle.jdbc.driver.OracleDriver");
- }
- catch(ClassNotFoundException e )
- {
- System.err.print("ERROR: Could not load database driver -> ");
- System.err.println(e.getMessage());
- System.exit(1);
- }
- String uri = "jdbc:oracle:thin:@//ikar.elka.pw.edu.pl:1521/elka.elka.pw.edu.pl";
- String user = "jsejdak";
- String password = "jsejdak";
- try
- {
- dbConnection = DriverManager.getConnection(uri, user, password);
- }
- catch(SQLException e)
- {
- System.err.print("ERROR: Could not connect to database -> ");
- System.err.println(e.getMessage());
- System.exit(1);
- }
- }
- /**
- * Creates connection and logs into data base
- * @return 0 - success, 1 - failure
- */
- public int logIn(String login, String password) throws SQLException
- {
- Statement s = dbConnection.createStatement();
- ResultSet rset = s.executeQuery("SELECT haslo FROM handlowcy "
- + "WHERE id_pracownika = "
- + login);
- rset.next();
- String storedPassword = rset.getString(1);
- rset.close();
- s.close();
- if(password.equals(storedPassword))
- return 0;
- else
- return 1;
- }
- public int logOut()
- {
- try
- {
- if(dbConnection != null)
- dbConnection.close();
- }
- catch(SQLException e)
- {
- System.err.print("ERROR: could not disconnect from database -> ");
- System.err.println(e.getMessage());
- }
- return 0;
- }
- private Connection dbConnection = null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement