Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. public class MySqlConnection {
  2. private static Connection conn;
  3.  
  4. public static Connection getConn() {
  5. try {
  6. Context initContext = new InitialContext() ;
  7. Context envContext = (Context)initContext.lookup("java:/comp/env") ;
  8. DataSource ds = (DataSource) envContext.lookup("jdbc/joinmyparty") ;
  9. conn = ds.getConnection();
  10.  
  11. } catch (NamingException e) {
  12. System.out.println("Cannot get connection: " + e);
  13. } catch (SQLException e) {
  14. System.out.println("Cannot get connection: " + e);
  15. }
  16. return conn;
  17. }
  18.  
  19. <?xml version="1.0" encoding="UTF-8"?>
  20.  
  21. <WatchedResource>WEB-INF/web.xml</WatchedResource>
  22. <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
  23. <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
  24.  
  25. <Resource url="jdbc:mysql://db:3306/joinmyparty"
  26. driverClassName="com.mysql.jdbc.Driver" password="mypassword"
  27. username="myusername" maxWait="10000" maxIdle="30"
  28. maxActive="100" type="javax.sql.DataSource" auth="Container"
  29. name="jdbc/joinmyparty" validationQuery="select 1" testOnBorrow="true"/>
  30.  
  31. </Context>
  32.  
  33. description : this server has encountered an internal error which prevents it from fulfilling your request
  34.  
  35. exception
  36.  
  37. java.lang.NullPointerException
  38. com.picco.user.dao.UserDao.findByEmail(UserDao.java:40)
  39. com.picco.user.servlet.Index.doGet(Index.java:56)
  40. javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
  41. javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
  42. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
  43.  
  44. try {
  45. UserDao udao = new UserDao();
  46. User u = udao.findByEmail(myCookieVal);
  47. SongDao sdao = new SongDao();
  48. ArrayList<Song> list = sdao.getAllSongs(u.getId());
  49. Random rd = new Random();
  50. int count = udao.count();
  51. request.setAttribute("currentSong", list.get(rd.nextInt(list.size())));
  52. request.setAttribute("songList", list);
  53. request.setAttribute("partyCount", count);
  54. this.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
  55. } catch(SQLException e) {
  56. e.printStackTrace();
  57. } finally {
  58. HsqlConnection.closeInstance();
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement