Advertisement
Guest User

Untitled

a guest
May 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. package csci3030u.a3;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5.  
  6. import com.mysql.jdbc.Connection;
  7. import com.mysql.jdbc.Statement;
  8.  
  9. public class CreateTable_A3 {
  10.  
  11. public static void main(String[] args) {
  12. try {
  13. Class.forName("com.mysql.jdbc.Driver");
  14. } catch(Exception e) {
  15. System.out.println("Driver not loaded."); System.exit(0);
  16. }
  17.  
  18. try {
  19. String conn_string = "jdbc:mysql://localhost/uoit_schedule";
  20. Connection con = (Connection) DriverManager.getConnection(
  21. conn_string, "root", "");
  22.  
  23. Statement stmt = (Statement) con.createStatement();
  24.  
  25. ResultSet result = stmt.executeQuery("SELECT * FROM Movies");
  26.  
  27. int numCols = result.getMetaData().getColumnCount();
  28. System.out.println("There are " + numCols + " columns.");
  29.  
  30. while(result.next())
  31. {
  32. String title = result.getString(1);
  33. String desc = result.getString(numCols);
  34. System.out.println("> " + title
  35. + " description = " + desc);
  36. }
  37.  
  38. result.close();
  39. con.close();
  40. } catch(Exception e) {
  41. System.out.println(e.getMessage());
  42. System.out.println("Driver not loaded."); System.exit(0);
  43. }
  44.  
  45. }
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement