What does setAutoCommit(false) do

A JDBC connection is created in auto-commit mode by default. This means that each individual SQL statement is treated as a transaction and will be automatically committed as soon as it is executed. If you require two or more statements to be grouped into a transaction then you need to disable auto-commit mode using below … Read more

What is the difference between PreparedStatement vs Statement

Which One Will You Use Statement or PreparedStatement? Or Which One to Use When (Statement/PreparedStatement)? Compare PreparedStatement vs Statement By Java API definitions: Statement is a object used for executing a static SQL statement and returning the results it produces. PreparedStatement is a SQL statement which is precompiled and stored in a PreparedStatement object. This object can then be … Read more

What does Class.forName() Method do

Method forName() is a static method of java.lang.Class. This can be used to dynamically load a class at run-time. Class.forName() loads the class if its not already loaded. It also executes the static block of loaded class. Then this method returns an instance of the loaded class. So a call to Class.forName(‘MyClass’) is going to … Read more

How to do Database Connection Using JDBC thin Driver

This is one of the most commonly asked questions from JDBC fundamentals, and knowing all the steps of JDBC connection is important. import java.sql.*; class JDBCTest { public static void main (String args []) throws Exception { //Load driver class Class.forName (“oracle.jdbc.driver.OracleDriver”); //Create connection Connection conn = DriverManager.getConnection (“jdbc:oracle:thin:@hostname:1526:testdb”, “scott”, “tiger”); // @machineName:port:SID,   userid,  password   Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(“select ‘Hi’ from dual”); while (rs.next()) System.out.println (rs.getString(1));   // Print col 1 => Hi stmt.close(); } } To establish a database connection using JDBC thin driver in Core Java, you typically follow … Read more

What is Connection Pooling? What Are The Advantages of Using a Connection Pool

Connection Pooling is a technique used for sharing the server resources among requested clients. It was pioneered by database vendors to allow multiple clients to share a cached set of connection objects that provides access to a database. Getting connection and disconnecting are costly operation, which affects the application performance, so we should avoid creating … Read more