Advertisement
Guest User

Untitled

a guest
Nov 20th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public class Console {
  2.  
  3. String sql;
  4. Statement stmt;
  5. Connection conn;
  6. ResultSet rs;
  7.  
  8. //Category Total
  9. public static double num;
  10.  
  11. public Console(){
  12. try{
  13. Class.forName("com.mysql.jdbc.Driver");
  14. System.out.println("Connecting to database...");
  15. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/database?autoReconnect=true&useSSL=false","user","password");
  16. stmt = conn.createStatement();
  17. System.out.println("Connected database successfully...");
  18.  
  19. sql = "SELECT sum(a) FROM table";
  20. while(rs.next()) {
  21. rs = stmt.executeQuery(sql);
  22. num = rs.getDouble("sum(a)");
  23. }
  24. } catch(Exception e) {
  25. e.printStackTrace();
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement