Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

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);

        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery("SELECT * FROM employee6");
        ResultSetMetaData md = rs.getMetaData();
        int col = md.getColumnCount();
        System.out.println("Number of Column : " + col);
        for (int i = 1; i <= col; i++) {
            String col_name = md.getColumnName(i);
            System.out.println(col_name);
        }
    }
}