Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package csci3030u.a3;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- public class CreateTable_A3 {
- public static void main(String[] args) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- } catch(Exception e) {
- System.out.println("Driver not loaded."); System.exit(0);
- }
- try {
- String conn_string = "jdbc:mysql://localhost/uoit_schedule";
- Connection con = (Connection) DriverManager.getConnection(
- conn_string, "root", "");
- Statement stmt = (Statement) con.createStatement();
- ResultSet result = stmt.executeQuery("SELECT * FROM Movies");
- int numCols = result.getMetaData().getColumnCount();
- System.out.println("There are " + numCols + " columns.");
- while(result.next())
- {
- String title = result.getString(1);
- String desc = result.getString(numCols);
- System.out.println("> " + title
- + " description = " + desc);
- }
- result.close();
- con.close();
- } catch(Exception e) {
- System.out.println(e.getMessage());
- System.out.println("Driver not loaded."); System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement