Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;

public class Main {
    public static void main(String[] argv) throws Exception {
        String driver = "com.mysql.jdbc.Driver";
        String user = "root";
        String pass = "root";

        Class.forName(driver);
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", user, pass);

        DatabaseMetaData dbm = con.getMetaData();
        String[] types = { "TABLE" };
        ResultSet rs = dbm.getTables(null, null, "%", types);
        System.out.println("Table name:");
        while (rs.next()) {
            String table = rs.getString("TABLE_NAME");
            System.out.println(table);
            con.close();
        }

    }
}