Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
    public static void main(String[] args) throws Exception {
        System.out.println("Count number of rows in a specific table!");
        Connection con = null;
        int count = 0;
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jdbctutorial", "root", "root");

        Statement st = con.createStatement();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        ResultSet res = st.executeQuery("SELECT COUNT(*) FROM EMP");
        while (res.next()) {
            count = res.getInt(1);
        }
        System.out.println("Number of row:" + count);
    }
}