JDBC

Execute procedure with CallableStatement JDBC

In the following program a procedure called getMe is executed using CallableStatement where a value is sent and another value is accessed. Here x is IN number and y is OUT number. CallableStatement along with PreparedStatement is fully discussed in Difference between Statement, PreparedStatement, CallableStatement. Example on Execute procedure CallableStatement Following is the SQL procedure. …

Execute procedure with CallableStatement JDBC Read More »

Dynamic SQL with PreparedStatement JDBC

In the following program, an Employee record is inserted using PreparedStatement(executing dynamic SQL statements). PreparedStatement along with CallableStatement is fully discussed in Difference between Statement, PreparedStatement, CallableStatement. Example on PreparedStatement JDBC import java.sql.*; import java.io.*; public class PreparedDemo { public static void main(String args[]) throws Exception { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con = DriverManager.getConnection(“jdbc:odbc:snrao”, “scott”, “tiger”); // …

Dynamic SQL with PreparedStatement JDBC Read More »

Difference Statement PreparedStatement CallableStatement

Statement vs PreparedStatement vs CallableStatement We know earlier, Statement interface works as a courier service between a Java (JDBC) program and database. There comes 3 types Statement interfaces in JDBC API doing the same job but used for different purposes. Let us see how they differ in Statement vs PreparedStatement vs CallableStatement and use them …

Difference Statement PreparedStatement CallableStatement Read More »

Drop Table JDBC

Drop Table JDBC Following Drop Table JDBC code deletes the table Employee. All the records also deleted with the table. drop table SQL command is used. Example on Drop Table JDBC import java.sql.*; public class DeleteTable { public static void main(String args[]) throws Exception { // 3 standard JDBC statements as usual Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con=DriverManager.getConnection(“jdbc:odbc:snrao”,”scott”,”tiger”); …

Drop Table JDBC Read More »

Delete Record JDBC Example

Delete Record JDBC Example. The Employee ID is taken from keyboard input. Example on Delete Record JDBC Example import java.sql.*; import java.io.*; public class DeleteRecord { public static void main(String args[]) throws Exception { // to take input from the user BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println(“Please Enter the ID no:”); String str=br.readLine(); int …

Delete Record JDBC Example Read More »

Select Records JDBC Example

Select Records JDBC Example: To retrieve records from Employee table in Oracle Database. By the time this program is executed, see some records exist in Employee table. Example on Select Records JDBC Example import java.sql.*; public class RetrieveRecords { public static void main(String args[]) throws Exception { // standard 3 JDBC statements Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con …

Select Records JDBC Example Read More »