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

What is a Stored Procedure? How to Call Stored Procedure Using JDBC API

Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters. Stored … Read more

What Are The Types of Statements in JDBC

the JDBC API has 3 Interfaces, (1. Statement, 2. PreparedStatement, 3. CallableStatement ). The key features of these are as follows: Statement This interface is used for executing a static SQL statement and returning the results it produces. The object of Statement class can be created using Connection.createStatement() method. PreparedStatement A SQL statement is pre-compiled and … Read more