Advertisement
Guest User

Untitled

a guest
Mar 8th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. import java.io.Serializable;
  2. import javax.enterprise.context.SessionScoped;
  3. // or import javax.faces.bean.SessionScoped;
  4. import javax.inject.Named;
  5. /* include package for SHA-256 encryption */
  6. import java.security.NoSuchAlgorithmException;
  7. /* include SQL Packages */
  8. import java.sql.Connection;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12. import javax.sql.DataSource;
  13. import javax.annotation.Resource;
  14. import javax.faces.context.FacesContext;
  15. import javax.inject.Inject;
  16. import javax.servlet.http.HttpServletRequest;
  17. import javax.servlet.http.HttpSession;
  18. // or import javax.faces.bean.ManagedBean;
  19.  
  20. import org.glassfish.osgicdi.OSGiService;
  21.  
  22. @Named("DashboardController")
  23.  
  24. @SessionScoped
  25.  
  26. public class Dashboard implements Serializable {
  27.  
  28. private String storedPassword = null;
  29. private String stringzoro = null;
  30. private String stringone = null;
  31. private String stringtwo = null;
  32. private String SQL_Statement = null;
  33.  
  34.  
  35. public Dashboard() throws SQLException{
  36. GetVariablesDB();
  37. }
  38.  
  39. /* Call the Oracle JDBC Connection driver */
  40. @Resource(name="jdbc/Oracle")
  41. private DataSource ds;
  42.  
  43.  
  44. public String getUser(){
  45. return stringzoro;
  46. }
  47.  
  48. public String getPassword(){
  49. return stringone;
  50. }
  51.  
  52.  
  53.  
  54.  
  55. private void GetVariablesDB() throws SQLException {
  56.  
  57. if (ds == null) throw new SQLException();
  58. Connection conn = ds.getConnection();
  59. if (conn == null) throw new SQLException();
  60.  
  61. try {
  62. conn.setAutoCommit(false);
  63. boolean committed = false;
  64. try {
  65. SQL_Statement = "SELECT * from GLOBALSETTINGS";
  66.  
  67. PreparedStatement passwordQuery = conn.prepareStatement(SQL_Statement);
  68.  
  69. ResultSet result = passwordQuery.executeQuery();
  70.  
  71. if(result.next()){
  72. stringzoro= result.getString("SessionTTL");
  73. stringone = result.getString("MAXACTIVEUSERS");
  74. stringtwo = result.getString("ACTIVEUSERS");
  75. }
  76.  
  77. conn.commit();
  78. committed = true;
  79. } finally {
  80. if (!committed) conn.rollback();
  81. }
  82. }
  83. finally {
  84. conn.close();
  85.  
  86. }
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement