JDBC

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 »

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 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 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 »

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 »

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 Types and Concurrency

ResultSet Types Concurrency JDBC Overloaded createStatement() Method (knowledge required for ResultSet Types Concurrency JDBC). Before going into programming it is required to know more about createStatement() method of Connection interface. This method can have parameters. You know the following Statement object creation earlier. Statement stmt = con.createStatement(); The createStatement() method of Connection interface returns an …

JDBC ResultSet Types and Concurrency Read More »

Scrollable ResultSet

You retrieved records from database earlier in Select Records Example by iterating the records with the ResultSet object as follows. In the same example, you also have seen the ResultSet cursor movement in while loop. while(res.next()) { System.out.println(res.getInt(1) + “\t” + res.getString(2) + “\t” + res.getDouble(3)); } The above loop prints the records from top …

Scrollable ResultSet Read More »

Retrieve File JDBC

You have seen earlier how to store a file in database table office. Let us retrieve the file (Retrieve File JDBC), "Expenditure.txt" from table and write into another file "Liabilities.txt". Example in Retrieve File JDBC import java.io.*; import java.sql.*; public class RetrieveFile { public static void main(String[] args) throws Exception { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con = …

Retrieve File JDBC Read More »

Insert File JDBC

To store a file in Oracle table though JDBC (Insert File JDBC) Before going into execution, create table by name office with columns FILEID (number) and FILENAME (CLOB). Example on Insert File JDBC import java.sql.*; public class FileInsert { public static void main(String args[]) throws Exception { Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); Connection con = DriverManager.getConnection(“jdbc:odbc:snrao”, “scott”, “tiger”); PreparedStatement …

Insert File 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 »