Advertisement
Guest User

Untitled

a guest
Feb 1st, 2012
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. package org.DX_57.osgi.SH_27.impl;
  2.  
  3. import java.sql.Connection;
  4. import javax.sql.DataSource;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import javax.annotation.Resource;
  9. import org.DX_57.osgi.SH_27.api.SessionHandle;
  10.  
  11. public class SessionHandleImpl implements SessionHandle {
  12.  
  13. @Resource(name="jdbc/Oracle")
  14. DataSource ds;
  15.  
  16. public String CheckUserDB(String userToCheck) throws SQLException {
  17. String storedPassword = null;
  18. String error_Message = null;
  19. String SQL_Statement = null;
  20. String error_Database = null;
  21.  
  22. if (ds == null) throw new SQLException( error_Database = "No data source");
  23. Connection conn = ds.getConnection();
  24. if (conn == null) throw new SQLException( error_Database = "No connection");
  25.  
  26. try {
  27. conn.setAutoCommit(false);
  28. boolean committed = false;
  29. try {
  30. SQL_Statement = "SELECT Passwd from USERS WHERE Username = ?";
  31.  
  32. PreparedStatement passwordQuery = conn.prepareStatement(SQL_Statement);
  33. passwordQuery.setString(1, userToCheck);
  34.  
  35. ResultSet result = passwordQuery.executeQuery();
  36.  
  37. if(result.next()){
  38. storedPassword = result.getString("Passwd");
  39. }
  40.  
  41. conn.commit();
  42. committed = true;
  43. } finally {
  44. if (!committed) conn.rollback();
  45. }
  46. }
  47. finally {
  48. conn.close();
  49.  
  50. }
  51.  
  52. return storedPassword;
  53. }
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement