Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Product summary:
- - IDE: Eclipse
- - Build: Maven
- - Framework: Vaadin
- - Server: WildFly 10.0.0
- - СУБД: PostgreSQL
- @SuppressWarnings("serial")
- public class DatabaseHelper implements Serializable {
- private JDBCConnectionPool connectionPool = null;
- private static ResourceBundle bundle = ResourceBundle.getBundle("rts.data.databaseHelper");
- public DatabaseHelper() {
- initConnectionPool();
- }
- private void initConnectionPool() {
- try {
- connectionPool = new SimpleJDBCConnectionPool("org.postgresql.Driver",bundle.getString("connectionUri") ,bundle.getString("userName"), bundle.getString("password"), 2, 2);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public JDBCConnectionPool getConnectionPool() {
- return connectionPool;
- }
- }
- connectionUri=jdbc:postgresql://localhost:5432/db.risk
- userName=postgres
- password=*******
- loginButton = new Button("Войти",
- new Button.ClickListener() {
- private static final long serialVersionUID = -5514448801678437295L;
- @Override
- public void buttonClick(ClickEvent event) {
- JDBCConnectionPool connectionPool = app.getDbHelper().getConnectionPool();
- Connection conn = null;
- System.out.println(Crypto.getEncodedStringAlg1(username.getValue(), paswd.getValue()));
- try {
- conn = connectionPool.reserveConnection();
- conn.setAutoCommit(false);
- CallableStatement proc = conn.prepareCall(
- "SELECT " +
- " usr.* " +
- "FROM " +
- " public.users usr " + //user_s
- "WHERE " +
- " username = ? and password = ?");
- proc.setString(1, username.getValue());
- proc.setString(2, Crypto.getEncodedStringAlg1(username.getValue(), paswd.getValue()));
- ResultSet rs = proc.executeQuery();
- if (rs != null && rs.next()) {
- UI.getCurrent().getSession().setAttribute("users_id", rs.getInt("id"));
- UI.getCurrent().getSession().setAttribute("users_first_name", rs.getString("first_name"));
- UI.getCurrent().getSession().setAttribute("users_surname", rs.getString("surname"));
- UI.getCurrent().getSession().setAttribute("users_role", rs.getInt("role"));
- if (rs.getInt("role")==2){
- app.getNavigator().navigateTo(MyUI.OperView);
- }
- else
- Notification.show("Ошибка:", " Не достаточно прав для входа в систему", Notification.Type.ERROR_MESSAGE);
- username.setValue("");
- paswd.setValue("");
- }
- else
- Notification.show("Ошибка:", " имя пользователя или пароль не верно", Notification.Type.ERROR_MESSAGE);
- conn.close();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- connectionPool.releaseConnection(conn);
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement