Search This Blog

Saturday, January 25, 2025

Java to Oracle database Connection Using JDBC

Oracle database.
// Java Program to Establish Connection 
// in JDBC with Oracle Database

// Importing database
import java.sql.*;
// Importing required classes
import java.util.*;

// Main class
class Main {

    // Main driver method
    public static void main(String a[])
    {

        // Creating the connection using Oracle DB
        // Note: url syntax is standard, so do grasp
        String url = "jdbc:oracle:thin:@localhost:1521:xe";

        // Username and password to access DB
        // Custom initialization
        String user = "system";
        String pass = "12345";

        // Entering the data
        Scanner k = new Scanner(System.in);

        System.out.println("enter name");
        String name = k.next();

        System.out.println("enter roll no");
        int roll = k.nextInt();

        System.out.println("enter class");
        String cls = k.next();

        // Inserting data using SQL query
        String sql = "insert into student1 values('" + name
                     + "'," + roll + ",'" + cls + "')";

        // Connection class object
        Connection con = null;

        // Try block to check for exceptions
        try {

            // Registering drivers
            DriverManager.registerDriver(
                new oracle.jdbc.OracleDriver());

            // Reference to connection interface
            con = DriverManager.getConnection(url, user,
                                              pass);

            // Creating a statement
            Statement st = con.createStatement();

            // Executing query
            int m = st.executeUpdate(sql);
            if (m == 1)
                System.out.println(
                    "inserted successfully : " + sql);
            else
                System.out.println("insertion failed");

            // Closing the connections
            con.close();
        }

        // Catch block to handle exceptions
        catch (Exception ex) {
            // Display message when exceptions occurs
            System.err.println(ex);
        }
    }
}

Saturday, January 18, 2025

Confirmation Alert Before Submit / Conditional Button execution using one button JavaScript in Oracle Apex

Using below code you can take a confirmation before execution even you can do conditional button press and execution.

apex.message.confirm( "Would you like to submit for approval? Click OK to continue or Cancel to return to the page", function( okPressed ) { if( okPressed ) { if (apex.item("P23_ITEM").isEmpty()) { apex.page.submit( { request: "CREATE" , showWait: true, } ); } else { apex.page.submit( { request: "SAVE" , showWait: true, } ); } } else { // this code will execute if cancel button pressed apex.item("P23_ITEM2").setValue("N"); } });

Friday, January 17, 2025

Interactive Grid Alternating Row Color

1. Put the CSS into Page properties Inline-> 

.customAlternatingRow .a-IRR-table tr:nth-child(odd) td{background-color:#bac3cc}

.customAlternatingRow .a-IRR-table tr:nth-child(even) td{background-color:#dceaf7}

.customRowHighlight .a-IRR-table tr:hover td{background-color:rgba(103,159,214,.55)}


2. Put the below Class code into the Region CSS Class  

customAlternatingRow customRowHighlight


Tuesday, January 14, 2025

Audit Log Sample Trigger

 create or replace TRIGGER "SCHEMA"."UDS_CALL_LOG_INFO_BIU" 

    BEFORE INSERT OR UPDATE 
    ON "APEX_UDS"."UDS_CALL_LOG_INFO"
    FOR EACH ROW
BEGIN
    IF INSERTING THEN
       IF :NEW.MASTER_ID IS NULL THEN
           SELECT UDS_CALL_LOG_INFO_SEQ.NEXTVAL
           INTO :NEW.MASTER_ID
           FROM DUAL;
         END IF;

         :NEW.CREATED_DATE := LOCALTIMESTAMP;
         :NEW.CREATED_BY:=nvl(v('APP_USER'),USER);
    ELSIF UPDATING THEN 
         :NEW.EDIT_DATE := LOCALTIMESTAMP;
         :NEW.EDITED_BY:=nvl(v('APP_USER'),USER);
    END IF;
  EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line ('An error was encountered '||SQLCODE||' -ERROR- '||SQLERRM);
END UDS_CALL_LOG_INFO_BIU;

How to Implement Password Hide/Show in Login Page

Follow these steps to enable users to toggle between hiding and showing their password on the login page. Step 1: Add the Function and Glob...