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.SQLException;
import java.sql.Statement;

public class Main {
    public static void main(String[] args) throws Exception {
        if (conn != null) {
            System.out.println("Connection attempt was successful!");

            try {
                conn.close();
            } catch (SQLException ex) {
                ex.printStackTrace();
                System.out.println("Problem closing the connection");
            }
        }
    }

    static Connection conn;

    static Statement st;

    static {
        try {
            // Step 1: Load the JDBC driver.
            Class.forName("org.hsqldb.jdbcDriver");
            System.out.println("Driver Loaded.");
            // Step 2: Establish the connection to the database.
            String url = "jdbc:hsqldb:data/tutorial";

            conn = DriverManager.getConnection(url, "sa", "");
            System.out.println("Got Connection.");

            st = conn.createStatement();
        } catch (Exception e) {
            System.err.println("Got an exception! ");
            e.printStackTrace();
            System.exit(0);
        }
    }
}