Advertisement
Guest User

Untitled

a guest
Mar 8th, 2012
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 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 SQL Packages */
  6. import java.sql.Connection;
  7. import java.sql.PreparedStatement;
  8. import java.sql.ResultSet;
  9. import java.sql.SQLException;
  10. import java.util.ArrayList;
  11. import java.util.List;
  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. @SessionScoped
  24. public class Dashboard implements Serializable {
  25.  
  26. private String storedPassword = null;
  27. private String stringzoro = null;
  28. private String stringone = null;
  29. private String stringtwo = null;
  30. private String SQL_Statement = null;
  31. private String Password;
  32. private String User;
  33.  
  34. public Dashboard() throws SQLException {
  35. }
  36.  
  37. /* Call the Oracle JDBC Connection driver */
  38. @Resource(name = "jdbc/Oracle")
  39. private DataSource ds;
  40.  
  41. public String getUser() {
  42. return User;
  43. }
  44.  
  45. public void setUser(String User) {
  46. this.User = User;
  47. }
  48.  
  49. public String getPassword() {
  50. return Password;
  51. }
  52.  
  53. public void setPassword(String Password) {
  54. this.Password = Password;
  55. }
  56.  
  57.  
  58.  
  59. //connect to DB and get customer list
  60. public List<Dashboard> getDashboardList() throws SQLException {
  61.  
  62. if (ds == null) {
  63. throw new SQLException("Can't get data source");
  64. }
  65.  
  66. //get database connection
  67. Connection con = ds.getConnection();
  68.  
  69. if (con == null) {
  70. throw new SQLException("Can't get database connection");
  71. }
  72.  
  73. PreparedStatement ps = con.prepareStatement(
  74. "SELECT * from GLOBALSETTINGS");
  75.  
  76. //get customer data from database
  77. ResultSet result = ps.executeQuery();
  78.  
  79. List<Dashboard> list = new ArrayList<Dashboard>();
  80.  
  81. while (result.next()) {
  82. Dashboard cust = new Dashboard();
  83.  
  84. cust.setUser(result.getString("SessionTTL"));
  85. cust.setPassword(result.getString("MAXACTIVEUSERS"));
  86.  
  87.  
  88. //store all data into a List
  89. list.add(cust);
  90. }
  91.  
  92. return list;
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement