Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. import java.sql.*;
  2. import java.util.Properties;
  3.  
  4. public class Test {
  5.  
  6. // Connection string. cs348 is the database the program is trying to connection
  7. // is connecting to,127.0.0.1 is the local loopback IP address for this machine, user name for the connection
  8. // is root, password is cs348
  9. private static final String CONNECTION_STRING =
  10. "jdbc:mysql://127.0.0.1/tpch?user=root&password=cs348&Database=tpch;";
  11.  
  12.  
  13. public static void main(String[] args) throws
  14. ClassNotFoundException,SQLException
  15. {
  16. // Try to connect
  17. Connection con = DriverManager.getConnection(CONNECTION_STRING);
  18. System.out.println("Connection Established");
  19.  
  20. String query = "SELECT COUNT(*) FROM LINEITEM AS CNT";
  21. Statement stmt = con.createStatement();
  22. ResultSet rs = stmt.executeQuery(query);
  23. while (rs.next()) {
  24. System.out.println(rs.getString(1));
  25. }
  26.  
  27. con.close();
  28. }
  29.  
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement