Guest User

Untitled

a guest
Apr 16th, 2016
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. <%--
  2. Document : index
  3. Created on : 16-Apr-2016, 1:06:00 PM
  4. Author : wilianto
  5. --%>
  6. <%@page import="java.sql.ResultSet"%>
  7. <%@page import="java.sql.Statement"%>
  8. <%@page import="java.sql.DriverManager"%>
  9. <%@page import="java.sql.Connection"%>
  10. <%@page import="java.sql.SQLException"%>
  11. <%@ page contentType="text/html" pageEncoding="UTF-8" %>
  12. <!DOCTYPE html>
  13. <html>
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  16. <title>JSP Page</title>
  17. </head>
  18. <body>
  19. <%
  20. //create connection
  21. String user = "wilianto";
  22. String pass = "";
  23. String driver = "org.apache.hive.jdbc.HiveDriver";
  24. String url = "jdbc:hive2://localhost:10000/default";
  25. Class.forName(driver).newInstance();
  26. Connection con = DriverManager.getConnection(url, user, pass);
  27. if(con == null){
  28. out.println("Not connected!");
  29. }else{
  30. out.println("Connected!");
  31. }
  32.  
  33. //do query
  34. Statement statement = con.createStatement();
  35. ResultSet rs = statement.executeQuery("SELECT * FROM destination_trends_summary");
  36. while(rs.next()){
  37. out.println(rs.getString("destination") + ", " + rs.getString("post_date") + ", " + rs.getString("qty") + "<br>");
  38. }
  39. %>
  40.  
  41. <h1>Hello World!</h1>
  42. <%
  43. out.println("Your IP address is " + request.getQueryString());
  44. %>
  45. </body>
  46. </html>
Add Comment
Please, Sign In to add comment