0% found this document useful (0 votes)
4 views

CallableStatement_DyanamicQueryExecution

The document is a Java program that demonstrates how to use a CallableStatement to execute a stored procedure in an Oracle database. It includes steps for registering the JDBC driver, establishing a database connection, creating a CallableStatement, executing a query with parameters, and closing the connection. Error handling is also implemented to catch any SQL exceptions during the process.

Uploaded by

lalitpatil784636
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

CallableStatement_DyanamicQueryExecution

The document is a Java program that demonstrates how to use a CallableStatement to execute a stored procedure in an Oracle database. It includes steps for registering the JDBC driver, establishing a database connection, creating a CallableStatement, executing a query with parameters, and closing the connection. Error handling is also implemented to catch any SQL exceptions during the process.

Uploaded by

lalitpatil784636
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.sql.

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

public class CallableStatementStaticQueryDemo


{
public static void main(String args[])
{
try
{
//1. Register the Driver
Driver d = new oracle.jdbc.driver.OracleDriver();
DriverManager.registerDriver(d);
System.out.println("Driver Registered Succesfully...!!");

//2. Get the Connection


Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system",
"admin");
System.out.println("Database Connection Established...!!");

//3. Create Statement Object


CallableStatement cstmt = con.prepareCall("{CALL
getprodata(?,?)}");

cstmt.setInt(1, 10);
cstmt.setString(2, "Chirag");

//4. Execute the Query


cstmt.execute();
System.out.println("Query Executed Successfully...!!");

//5. Close the Connection


System.out.println("Connection is Closed...!!");
}

catch(SQLException e)
{
System.out.println("Error in Database Connectivity...!!");
}
}
}

You might also like