Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package main;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.List;
- import javax.naming.NamingException;
- /**
- *
- * @author Illusion
- */
- public class user {
- Connection conn = null;
- String sql;
- Statement stmt = null;
- ResultSet rs;
- boolean found;
- public boolean checkUser(String user, String pass) throws Exception
- {
- try {
- sql = "SELECT * FROM user WHERE username='" + user + "' AND password='" + pass + "';";
- conn = db.getConn.getConnect();
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- if (rs.next() == true) {
- System.out.print("found");
- found = true;
- } else {
- System.out.print("not found");
- found = false;
- }
- stmt.close();
- conn.close();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (NamingException e) {
- e.printStackTrace();
- }catch(Exception e) {
- e.printStackTrace();
- }
- return found;
- }
- List lista = new ArrayList();
- public List <Integer> getUsersList() throws Exception
- {
- try{
- sql = "SELECT iduser FROM user";
- conn = db.getConn.getConnect();
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- while (rs.next()){
- lista.add(rs.getInt("iduser"));
- }
- stmt.close();
- conn.close();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (NamingException e) {
- e.printStackTrace();
- }
- return lista;
- }
- String name;
- public String getName(Integer id) throws Exception
- {
- try {
- sql = "SELECT * FROM user WHERE iduser='" + id + "';";
- conn = db.getConn.getConnect();
- stmt = conn.createStatement();
- rs = stmt.executeQuery(sql);
- if (rs.next() == true) {
- name = rs.getString("username");
- } else {
- System.out.print("not found");
- }
- stmt.close();
- conn.close();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (NamingException e) {
- e.printStackTrace();
- }catch(Exception e) {
- e.printStackTrace();
- }
- return name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement