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.Statement;

public class Main {
    public static void main(String[] args) throws Exception {
        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "jdbc4";
        String driver = "com.mysql.jdbc.Driver";
        String userName = "root";
        String password = "root";

        Class.forName(driver).newInstance();

        Connection conn = DriverManager.getConnection(url + dbName, userName, password);
        Statement st = conn.createStatement();

        int rows = st.executeUpdate("INSERT INTO Copyemployee SELECT * FROM employee");
        if (rows == 0) {
            System.out.println("Don't add any row!");
        } else {
            System.out.println(rows + " row(s)affected.");
            conn.close();
        }
    }
}