Found 34484 Articles for Programming

How to write a JDBC application which connects to multiple databases simultaneously?

Nancy Den
Updated on 30-Jul-2019 22:30:25

5K+ Views

To connect with a database, you need toRegister the Driver: Select the required database, register the Driver class of the particular database using the registerDriver() method of the DriverManager class or, the forName() method of the class named Class.DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get connection: Create a connection object by passing the URL of the database, username and password (of a user in the database) in string format, as parameters to the getConnection() method of the DriverManager class.Connection mysqlCon = DriverManager.getConnection(mysqlUrl, "root", "password");To connect to multiple databases in a single JDBC program you need to connect to the two (or more) databases simultaneously using ... Read More

What are bind variables? How to execute a query with bind variables using JDBC?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

6K+ Views

A bind variable is an SQL statement with a temporary variable as place holders which are later replaced with appropriate values. For example, if you have a table named employee in the database created as shown below:+---------+--------+----------------+ | Name | Salary | Location | +---------+--------+----------------+ | Amit | 30000 | Hyderabad | | Kalyan | 40000 | Vishakhapatnam | | Renuka | 50000 | Delhi | | Archana | ... Read More

What are the types of statements in JDBC?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

10K+ Views

There are three types of statements in JDBC namely, Statement, Prepared Statement, Callable statement.StatementThe Statement interface represents the static SQL statement. It helps you to create a general purpose SQL statements using Java.Creating a statementYou can create an object of this interface using the createStatement() method of the Connection interface.Create a statement by invoking the createStatement() method as shown below.Statement stmt = null; try { stmt = conn.createStatement( ); . . . } catch (SQLException e) { . . . } finally { . . . }Executing the ... Read More

What are the main classes and interfaces of JDBC?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

11K+ Views

JDBC API is available in two packages java.sql, core API and javax.sql JDBC optional packages. Following are the important classes and interfaces of JDBC.Class/interfaceDescriptionDriverManagerThis class manages the JDBC drivers. You need to register your drivers to this.It provides methods such as registerDriver() and getConnection().DriverThis interface is the Base interface for every driver class i.e. If you want to create a JDBC Driver of your own you need to implement this interface. If you load a Driver class (implementation of this interface), it will create an instance of itself and register with the driver manager.StatementThis interface represents a static SQL statement. ... Read More

How to establish connection with JDBC?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

1K+ Views

To connect with a database, you need to follow the steps given below:Step1: Register the driver: To develop a basic JDBC application, first of all, you need to register the driver with the DriverManager.You can register a driver in two ways, one is using registerDriver() method of the DriverManager class and, using forName() method of the class named Class.The registerDriver() method accepts an object of the Driver class, it registers the specified Driver with the DriverManager.Driver myDriver = new com.mysql.jdbc.Driver(); DriverManager.registerDriver(myDriver);The forName() method loads the specified class into the memory and thus it automatically gets registered.Class.forName("com.mysql.jdbc.Driver");Step2: Get Connection: Get the ... Read More

What is type4 driver of JDBC what are the advantages and disadvantages of it?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

859 Views

The Type 4 driver is the pure Java driver. It implements database specific protocol to communicate with the database directly. This driver is provided by the vender itself, this is flexible driver compared to other drivers.Advantages of type4 driverFollowing are the advantages of the type4 driver.It is purely developed in Java and it is the platform independent driver.Unlike type-1 driver there is no need to install OCI, ODBC functions.While using this driver there is no need for middleware server.Disadvantages of type4 driverFollowing are the disadvantages of type4 driver.Type-4 driver internally uses database specific proprietary protocol and it is database dependent. ... Read More

What is type3 driver of JDBC what are the advantages and disadvantages of it?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

656 Views

In a Type 3 driver, a three-tier approach is used to access databases. The JDBC clients use standard network sockets to communicate with a middleware application server. The socket information is then translated by the middleware application server into the call format required by the DBMS, and forwarded to the database server.This kind of driver is extremely flexible, since it requires no code installed on the client, a single driver can actually provide access to multiple databases. You can think of the application server as a JDBC "proxy, " meaning that it makes calls for the client application. As a ... Read More

What is type2 driver of JDBC what are the advantages and disadvantages of it?

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

715 Views

This driver is known as a native API driver. This driver receives the calls from Java application and converts them in to vender specific native API calls. Here, we need to install The vendor-specific driver on the client machines.If we change the Database, we have to change the native API, as it is specific to a database and they are mostly obsolete now, but you may realize some speed increase with a Type 2 driver because it eliminates ODBC's overhead.Advantages of type2 driverFollowing are the advantages of the type2 driver.This type of driver fastest among all the 4 types of ... Read More

What is type1 driver of JDBC what are the advantages and disadvantages of it?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

It is the ODBC – JDBC bridge driver, it acts as a bridge between JDBC and, ODBC database connectivity mechanism. Using this you can access the databases which support only ODBC. Initially, it is used extensively, since most of the databases supported only ODBC.Whenever Java application sends a request to the JDBC-ODBC bridge driver the request internally calls the ODBC equivalent function and the ODBC driver retrieves the result from the underlying database and sends it back to the JDBC-ODBC bridge driver.Advantages of type1 driverFollowing are the advantages of a type1 driver.Using this single driver, you can access different DataSource.You ... Read More

How many types of JDBC Drivers are there?

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

1K+ Views

There are 4 types of JDBC drivers namely, Type-1, Type-2, Type-3 and, Type-4.Type1 It is the ODBC − JDBC bridge driver, it acts as a bridge between JDBC and, ODBC database connectivity mechanism. Using this you can access the databases which support only ODBC. Initially, it is used extensively, since most of the databases supported only ODBC.Whenever Java application sends a request to the JDBC-ODBC bridge driver the request internally calls the ODBC equivalent function and the ODBC driver retrieves the result from the underlying database and sends it back to the JDBC-ODBC bridge driver.Advantages of type1 driverFollowing are the advantages ... Read More

Advertisements