Home » Core Java » sql » Page 11

sql

Batch statement execution example

With this example we are going to demonstrate how to execute a batch statement in Java. In particular we are going to insert 10 rows of data to a table. In short, to execute a batch statement you should: Load the JDBC driver, using the forName(String className) API method of the Class. In this example we use the MySQL JDBC ...

Read More »

Check database Batch support

This is an example of how to check if a database supports batch updates. Checking if a database supports batch updates implies that you should: Load the JDBC driver, using the forName(String className) API method of the Class. In this example we use the MySQL JDBC driver. Create a Connection to the database. Invoke the getConnection(String url, String user, String ...

Read More »

Set prefetch size of SQL query example

In this example we shall show you how to set the fetch size of an SQL query. When changing the fetch size of a database, every time data is fetched from the database, the number of rows fetched will be equal to the size specified. To set the fetch size of an SQL query one should perform the following steps: ...

Read More »

Get JDBC Connection parameters

With this example we are going to demonstrate how to get the JDBC Connection parameters. In short, to get the JDBC Connection parameters you should: Load the MySQL JDBC driver, using the forName(String className) API method of the Class. Get the Driver Instance. Invoke the getDriver(String url) of the DriverManager, using the database URL. Get available properties, using the getPropertyInfo(String ...

Read More »

Handle SQL Exceptions example

This is an example of how to handle SQL Exceptions in Java. Handling SQL Exceptions implies that you should: Load the JDBC driver, using the forName(String className) API method of the Class. In this example we use the Oracle JDBC driver. Create a Connection to the database. Invoke the getConnection(String url, String user, String password) API method of the DriverManager ...

Read More »

Handle SQL warning example

In this example we shall show you how to handle SQL Warnings in Java. To handle SQL Warnings one should perform the following steps: Load the JDBC driver, using the forName(String className) API method of the Class. In this example we use the Oracle JDBC driver. Create a Connection to the database. Invoke the getConnection(String url, String user, String password) ...

Read More »

Check if a database supports transactions

With this example we are going to demonstrate how to check if a database supports transactions. In short, to check if a database supports transactions you should: Load the JDBC driver, using the forName(String className) API method of the Class. In this example we use the Oracle JDBC driver. Create a Connection to the database. Invoke the getConnection(String url, String ...

Read More »

Commit/Rollback transaction example

This is an example of a commit and a rollback transaction in Java. Handling commit and rollback transactions in Java implies that you should: Load the JDBC driver, using the forName(String className) API method of the Class. In this example we use the Oracle JDBC driver. Create a Connection to the database. Invoke the getConnection(String url, String user, String password) ...

Read More »

Connect to Oracle database example

In this example we shall show you how to connect to Oracle Database. To connect to Oracle Database one should perform the following steps: Load the oracle.jdbc.driver.OracleDriver, using the forName(String className) API method of the Class, in order to connect to Oracle Database. Create a Connection to the database. Invoke the getConnection(String url, String user, String password) API method of ...

Read More »

Connect to SQLServer database example

With this example we are going to demonstrate how to connect to SQLServer Database in Java. In short, to connect to SQLServer Database you should: Load the NetDirect JDBC driver, using the forName(String className) API method of the Class, in order to connect to SQLServer Database. Create a Connection to the database. Invoke the getConnection(String url, String user, String password) ...

Read More »