Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
    private static final String DB_DRIVER = "oracle.jdbc.driver.OracleDriver";
    private static final String DB_CONNECTION = "jdbc:oracle:thin:@localhost:1521:YourDatabase";
    private static final String DB_USER = "user";
    private static final String DB_PASSWORD = "password";

    public static void main(String[] argv) throws Exception {
        Class.forName(DB_DRIVER);
        Connection dbConnection = DriverManager.getConnection(DB_CONNECTION, DB_USER, DB_PASSWORD);

        CallableStatement callableStatement = null;
        String insertStoreProc = "{call insertPERSON(?,?,?,?)}";

        java.util.Date today = new java.util.Date();
        callableStatement = dbConnection.prepareCall(insertStoreProc);
        callableStatement.setInt(1, 1000);
        callableStatement.setString(2, "name");
        callableStatement.setString(3, "system");
        callableStatement.setDate(4, new java.sql.Date(today.getTime()));

        callableStatement.executeUpdate();
        System.out.println("Record is inserted into PERSON table!");
        callableStatement.close();
        dbConnection.close();
    }
}