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.Date;
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 getPERSONByUserIdSql = "{call getPERSONByUserId(?,?,?,?)}";
        callableStatement = dbConnection.prepareCall(getPERSONByUserIdSql);

        callableStatement.setInt(1, 10);
        callableStatement.registerOutParameter(2, java.sql.Types.VARCHAR);
        callableStatement.registerOutParameter(3, java.sql.Types.VARCHAR);
        callableStatement.registerOutParameter(4, java.sql.Types.DATE);

        callableStatement.executeUpdate();

        String userName = callableStatement.getString(2);
        String createdBy = callableStatement.getString(3);
        Date createdDate = callableStatement.getDate(4);

        System.out.println("UserName : " + userName);
        System.out.println("CreatedBy : " + createdBy);
        System.out.println("CreatedDate : " + createdDate);
        callableStatement.close();
        dbConnection.close();
    }
}