Guest User

Untitled

a guest
Aug 4th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. JDBC - cannot find getConnection()
  2. package org.DX_57.osgi.SH_27.impl;
  3.  
  4. import java.sql.Connection;
  5. import java.sql.PreparedStatement;
  6. import java.sql.ResultSet;
  7. import java.sql.SQLException;
  8. import javax.activation.DataSource;
  9. import javax.annotation.Resource;
  10. import org.DX_57.osgi.SH_27.api.SessionHandle;
  11.  
  12.  
  13.  
  14. public class SessionHandleImpl implements SessionHandle {
  15.  
  16. @Resource(name="jdbc/Oracle") DataSource ds;
  17.  
  18. @Override
  19. public String sayHello(String name) {
  20. return "test2 " + name;
  21. }
  22.  
  23. @Override
  24. public String CheckUserDB(String userToCheck) {
  25. String storedPassword = null;
  26. String error_Message = null;
  27. String SQL_Statement = null;
  28. String error_Database = null;
  29.  
  30. Connection conn = ds.getConnection();
  31. if (conn == null) throw new SQLException(error_Database = "No connection");
  32.  
  33. try {
  34. conn.setAutoCommit(false);
  35. boolean committed = false;
  36. try {
  37. SQL_Statement = "SELECT Passwd from USERS WHERE Username = ?";
  38.  
  39. PreparedStatement passwordQuery = conn.prepareStatement(SQL_Statement);
  40. passwordQuery.setString(1, userToCheck);
  41.  
  42. ResultSet result = passwordQuery.executeQuery();
  43.  
  44. if(result.next()){
  45. storedPassword = result.getString("Passwd");
  46. }
  47.  
  48. conn.commit();
  49. committed = true;
  50. } finally {
  51. if (!committed) conn.rollback();
  52. }
  53. } finally {
  54. conn.close();
  55. }
  56.  
  57. /** if the user is not found or password don't match display error message*/
  58. if (storedPassword == null) {
  59. error_Message = "Invalid Username!";
  60. } else {
  61. error_Message = "Invalid Password!";
  62. }
  63.  
  64. return storedPassword;
  65. }
  66. }
  67.  
  68. import javax.activation.DataSource;
  69.  
  70. import javax.sql.DataSource;
Add Comment
Please, Sign In to add comment