Series: JDBC

Java connecting to database programs explained in simple terms and screenshots

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 »

Execute SQL Function CallableStatement JDBC

In the following program a function by name calculate() is executed from JDBC. The function includes one IN parameter, one OUT parameter and one return value (note that return value can be one only, but IN and INOUT can be of any number). CallableStatement along with PreparedStatement is fully discussed in Difference between Statement, PreparedStatement, …

Execute SQL Function CallableStatement JDBC Read More »

JDBC ResultSet Enhancement Update Methods Example

ResultSet methods JDBC JDBC 2.0 ResultSet enhancement operations include the methods to update, insert or delete a record without writing the SQL commands. That is, SQL commands need not be known, of course for CRUD operations. This is the greatness of ResultSet methods JDBC. Example on ResultSet methods JDBC import java.sql.*; public class Updates { …

JDBC ResultSet Enhancement Update Methods Example Read More »

JDBC ResultSet Update Record with Refresh Row

Refresh Row JDBC One of the new features of JDBC 2.0 is the introduction of updateXXX() methods in ResultSet interface. With these methods, without using SQL commands, a record in the table can be updated, inserted, deleted and now let us see updating a record with refreshRow() method. In the following code, a record’s old …

JDBC ResultSet Update Record with Refresh Row Read More »

How to find number of rows in the ResultSet object?

Number of rows in table JDBC There is no direct method in JDBC. In JDBC 1.0, the only way available is using while loop with a counter as follows. Example on number of rows in table JDBC with JDBC 1.0 style ResultSet res = stmt.executeQuery(“select * from Employee”); int counter = 0; while(res.next()) { counter++; …

How to find number of rows in the ResultSet object? Read More »

How to get number of columns in a table with JDBC?

Number of columns in table JDBC ResultSetMetaData interface includes many methods to find the metadata of a table like number of columns, name of each column etc. Following example prints the number of columns of table Employee. Example on number of columns in table JDBC import java.sql.*; public class MetaData { public static void main(String …

How to get number of columns in a table with JDBC? Read More »

How to get the name of column in a table with JDBC?

Column name JDBC ResultSetMetaData interface comes with methods to know the metadata of a table. Metadata is knowing the number of columns, name of each column etc. Example (of column name JDBC) prints the first column name and all the column names of table Employee. Example on column name JDBC import java.sql.*; public class MetaData …

How to get the name of column in a table with JDBC? Read More »

How to get column type of a column in a table with JDBC?

In the following example, all the Employee table column names and their data types are printed using methods of ResultSetMetaData like getColumnName() and getColumnType(). Example on column type JDBC import java.sql.*; public class GetDataInfo { public static void main(String args[]) throws Exception { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con = DriverManager.getConnection(“jdbc:odbc:snrao”,”scott”,”tiger”); Statement stmt = con.createStatement( ); ResultSet res …

How to get column type of a column in a table with JDBC? Read More »