Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.prgguru.jersey;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class DBConnection {
- /**
- * Method to create DB Connection
- *
- * @return
- * @throws Exception
- */
- @SuppressWarnings("finally")
- public static Connection createConnection() throws Exception {
- Connection con = null;
- try {
- Class.forName(Constants.dbClass);
- con = DriverManager.getConnection(Constants.dbUrl, Constants.dbUser, Constants.dbPwd);
- } catch (Exception e) {
- throw e;
- } finally {
- return con;
- }
- }
- /**
- * Method to check whether uemail and pwd combination are correct
- *
- * @param uemail
- * @param pwd
- * @return
- * @throws Exception
- */
- public static boolean checkLogin(String uemail, String pwd) throws Exception {
- boolean isUserAvailable = false;
- Connection dbConn = null;
- try {
- try {
- dbConn = DBConnection.createConnection();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Statement stmt = dbConn.createStatement();
- String query = "SELECT * FROM usuario WHERE email = '" + uemail
- + "' AND senha=" + "'" + pwd + "'";
- //System.out.println(query);
- ResultSet rs = stmt.executeQuery(query);
- while (rs.next()) {
- //System.out.println(rs.getString(1) + rs.getString(2) + rs.getString(3));
- isUserAvailable = true;
- }
- } catch (SQLException sqle) {
- throw sqle;
- } catch (Exception e) {
- // TODO Auto-generated catch block
- if (dbConn != null) {
- dbConn.close();
- }
- throw e;
- } finally {
- if (dbConn != null) {
- dbConn.close();
- }
- }
- return isUserAvailable;
- }
- /**
- * Method to insert uemail and pwd in DB
- *
- * @param name
- * @param uname
- * @param pwd
- * @return
- * @throws SQLException
- * @throws Exception
- */
- }
Add Comment
Please, Sign In to add comment