MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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

public class MainClass {
    public static void main(String[] arguments) {
        String data = "jdbc:odbc:YourSettings";
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn = DriverManager.getConnection(data, "", "");
            Statement st = conn.createStatement();
            ResultSet rec = st
                    .executeQuery("SELECT * FROM Coal WHERE (Country='" + arguments[0] + "') ORDER BY Year");
            while (rec.next()) {
                System.out.println(rec.getString(1) + "\t" + rec.getString(2) + "\t\t" + rec.getString(3) + "\t"
                        + rec.getString(4));
            }
            st.close();
        } catch (Exception e) {
            System.out.println("Error: " + e.toString() + e.getMessage());
        }
    }
}