Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1.  
  2. import java.sql.*;
  3. import java.io.PrintWriter;
  4.  
  5. public class GetIt {
  6.  
  7. public static void main(String args[]){
  8.  
  9. // Load and register a JDBC driver
  10. try {
  11. // Load the driver (registers itself)
  12. Class.forName("com.mysql.jdbc.Driver");
  13. } catch (Exception E) {
  14. System.err.println("Unable to load driver.");
  15. E.printStackTrace();
  16. }
  17. try {
  18. // Connect to the database
  19. Connection conn1;
  20. String dbUrl = "jdbc:mysql://proj309-ds-02.misc.iastate.edu";
  21. String user = "user";
  22. String password = "userPassword6!";
  23. conn1 = DriverManager.getConnection(dbUrl, user, password);
  24. System.out.println("*** Connected to the database ***");
  25.  
  26. // Create Statement and ResultSet variables to use throughout the
  27. // project
  28. Statement statement = conn1.createStatement();
  29. ResultSet rs;
  30.  
  31. statement.executeUpdate("use roll19");
  32. rs = statement.executeQuery("select * from dudTest");
  33. rs.next();
  34. System.out.println(rs.getString("testInt"));
  35.  
  36.  
  37. } catch (SQLException e) {
  38. System.out.println("SQLException: " + e.getMessage());
  39. System.out.println("SQLState: " + e.getSQLState());
  40. System.out.println("VendorError: " + e.getErrorCode());
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement