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

public class Main {
    public static void main(String[] args) throws Exception {
        String db_file_name_prefix = "c:\\mydbdir\\mydb";

        Connection con = null;
        Class.forName("org.hsqldb.jdbcDriver");

        con = DriverManager.getConnection("jdbc:hsqldb:file:" + db_file_name_prefix, // filenames
                "sa", // username
                ""); // password

        Statement statement = con.createStatement();
        ResultSet rs = statement.executeQuery("SELECT * FROM \"User\"");
        while (rs.next()) {
            System.out.print("ID: " + rs.getString("ID"));
            System.out.print(" first name: " + rs.getString("firstname"));
            System.out.println(" last name: " + rs.getString("lastname"));
        }
        statement.close();
        con.close();
    }
}