Notice that getter methods for a specific data type are used. Each column is printed separated by commas. Next the program traverses through the ResultSet using the next() method. The ResultSet object returned contains the results of the query.
Oracle database data type code#
In the example program a forward only ResultSet was all that was needed.Īfter creating the Statement object stmt the code then executes the query by calling the executeQuery method passing in a String for the query. How the ResultSet is ultimately going to be used will determine the proper createStatement method to call. The valid values for rsHoldability are ResultSet.HOLD_CURSORS_OVER_COMMIT and ResultSet.CLOSE_CURSORS_AT_COMMIT. Returns a Statement object that will generate ResultSet objects of the given type, concurrency and holdability. Statement createStatement(int rstType, int rsConcurrency, int rsHoldability) Valid rsConcurrency values are ResultSet.CONCUR_READ_ONLY and ResultSet.CONCUR_UPDATABLE. Valid rsTypes are: ResultSet.TYPE_FORWARD_ONLY, ResultSet.TYPE_SCROLL_INSENSITIVE and ResultSet.TYPE_SCROLL_SENSITIVE. Returns a Statement object that will generate ResultSet objects of the given type and concurrency.
Statement createStatement(int rsType, int rsConcurrency) Returns a Statement object that will generate ResultSet objects that have a forward only cursor and that are read only. The Connection object provides three methods in which to create a Statement object. (rset.getInt(1) + ", " +Īn SQL statement is executed within the context of a Connection so we need to use one of the methods provided by the Connection object to create the Statement. ResultSet rset = stmt.executeQuery("select employee_id, first_name, last_name, hire_date from employees") create the statement and execute the query OracleConnection ocon = (OracleConnection)ods.getConnection() OracleDataSource ods = new connect to the database and turn off auto commit create the Oracle DataSource and set the URL Extends PreparedStatement.īelow is a Java program that will process the same query presented above. Extends Statement.ĬallableStatement – execute and retrieve data from stored procedures. PreparedStatement – preparsed SQL statements with or without input (bind values) parameters. Statement – SQL statements with no input (bind values) parameters. There are three types of Statement objects in the package java.sql each specialized in a particular type of SQL statement. SQL> select employee_id, first_name, last_name, hire_date from employees ĮMPLOYEE_ID FIRST_NAME LAST_NAME HIRE_DATEĪ Statement object is used to send and execute SQL statements on a given connection. Using simple SQL statement such as the one below we will build a Java program using JDBC to execute the SQL and print out the results.
Oracle database data type series#
Note: The example programs presented in this series of post make use of the HR demonstration schema. The other two articles will look at the PreparedStatement and the CallableStatement.
Oracle database data type how to#
In this first post we look at the basics of the Statement interface and how to process simple queries.
In this three part series of posts we will look at fetching data from an Oracle Database using Java and JDBC.