Java DataSource, JDBC DataSource Example

Filed Under: Database

Java DataSource and JDBC DataSource programming is the way to work with database in our java programs. We have already seen that JDBC DriverManager can be used to get relational database connections. But when it comes to actual programming, we want more than just connections.

Java DataSource, JDBC DataSource, JDBC DataSource Example, MysqlDataSource, OracleDataSource

Java DataSource

Most of the times we are looking for loose coupling for connectivity so that we can switch databases easily, connection pooling for transaction management and distributed systems support. JDBC DataSource is the preferred approach if you are looking for any of these features in your application. Java DataSource interface is present in javax.sql package and it only declare two overloaded methods getConnection() and getConnection(String str1,String str2).

JDBC DataSource

It is the responsibility of different Database vendors to provide different kinds of implementation of DataSource interface. For example MySQL JDBC Driver provides basic implementation of DataSource interface with com.mysql.jdbc.jdbc2.optional.MysqlDataSource class and Oracle database driver implements it with oracle.jdbc.pool.OracleDataSource class.

These implementation classes provide methods through which we can provide database server details with user credentials. Some of the other common features provided by these JDBC DataSource implementation classes are;

  • Caching of PreparedStatement for faster processing
  • Connection timeout settings
  • Logging features
  • ResultSet maximum size threshold

JDBC DataSource Example

Let’s create a simple JDBC DataSource example project and learn how to use MySQL and Oracle DataSource basic implementation classes to get the database connection. Our final project will look like below image.

JDBC DataSource Example, Java DataSource, JDBC DataSource

Java JDBC DataSource – Database Setup

Before we get into our example programs, we need some database setup with table and sample data. Installation of MySQL or Oracle database is out of scope of this tutorial, so I will just go ahead and setup table with sample data.


--Create Employee table
CREATE TABLE `Employee` (
  `empId` int(10) unsigned NOT NULL,
  `name` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`empId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- insert some sample data
INSERT INTO `Employee` (`empId`, `name`)
VALUES
	(1, 'Pankaj'),
	(2, 'David');

commit;

CREATE TABLE "EMPLOYEE"
  (
    "EMPID"   NUMBER NOT NULL ENABLE,
    "NAME"    VARCHAR2(10 BYTE) DEFAULT NULL,
    PRIMARY KEY ("EMPID")
  );

Insert into EMPLOYEE (EMPID,NAME) values (10,'Pankaj');
Insert into EMPLOYEE (EMPID,NAME) values (5,'Kumar');
Insert into EMPLOYEE (EMPID,NAME) values (1,'Pankaj');
commit;

Now let’s move on to our java programs. For having database configuration loosely coupled, I will read them from property file.

db.properties file:


#mysql DB properties
MYSQL_DB_DRIVER_CLASS=com.mysql.jdbc.Driver
MYSQL_DB_URL=jdbc:mysql://localhost:3306/UserDB
MYSQL_DB_USERNAME=pankaj
MYSQL_DB_PASSWORD=pankaj123

#Oracle DB Properties
ORACLE_DB_DRIVER_CLASS=oracle.jdbc.driver.OracleDriver
ORACLE_DB_URL=jdbc:oracle:thin:@localhost:1521:orcl
ORACLE_DB_USERNAME=hr
ORACLE_DB_PASSWORD=oracle

Make sure that above configurations match with your local setup. Also make sure you have MySQL and Oracle DB JDBC jars included in the build path of the project.

Java JDBC DataSource – MySQL, Oracle Example

Let’s write a factory class that we can use to get MySQL or Oracle DataSource.


package com.journaldev.jdbc.datasource;

import java.io.FileInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

import oracle.jdbc.pool.OracleDataSource;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

public class MyDataSourceFactory {

	public static DataSource getMySQLDataSource() {
		Properties props = new Properties();
		FileInputStream fis = null;
		MysqlDataSource mysqlDS = null;
		try {
			fis = new FileInputStream("db.properties");
			props.load(fis);
			mysqlDS = new MysqlDataSource();
			mysqlDS.setURL(props.getProperty("MYSQL_DB_URL"));
			mysqlDS.setUser(props.getProperty("MYSQL_DB_USERNAME"));
			mysqlDS.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		return mysqlDS;
	}
	
	public static DataSource getOracleDataSource(){
		Properties props = new Properties();
		FileInputStream fis = null;
		OracleDataSource oracleDS = null;
		try {
			fis = new FileInputStream("db.properties");
			props.load(fis);
			oracleDS = new OracleDataSource();
			oracleDS.setURL(props.getProperty("ORACLE_DB_URL"));
			oracleDS.setUser(props.getProperty("ORACLE_DB_USERNAME"));
			oracleDS.setPassword(props.getProperty("ORACLE_DB_PASSWORD"));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return oracleDS;
	}
		
}

Notice that both Oracle and MySQL DataSource implementation classes are very similar, let’s write a simple test program to use these methods and run some test.


package com.journaldev.jdbc.datasource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

public class DataSourceTest {

	public static void main(String[] args) {
		
		testDataSource("mysql");
		System.out.println("**********");
		testDataSource("oracle");

	}

	private static void testDataSource(String dbType) {
		DataSource ds = null;
		if("mysql".equals(dbType)){
			ds = MyDataSourceFactory.getMySQLDataSource();
		}else if("oracle".equals(dbType)){
			ds = MyDataSourceFactory.getOracleDataSource();
		}else{
			System.out.println("invalid db type");
			return;
		}
		
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			con = ds.getConnection();
			stmt = con.createStatement();
			rs = stmt.executeQuery("select empid, name from Employee");
			while(rs.next()){
				System.out.println("Employee ID="+rs.getInt("empid")+", Name="+rs.getString("name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
				try {
					if(rs != null) rs.close();
					if(stmt != null) stmt.close();
					if(con != null) con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}

}

Notice that the client class is totally independent of any Database specific classes. This helps us in hiding the underlying implementation details from client program and achieve loose coupling and abstraction benefits.

When we run above test program, we will get below output.


Employee ID=1, Name=Pankaj
Employee ID=2, Name=David
**********
Employee ID=10, Name=Pankaj
Employee ID=5, Name=Kumar
Employee ID=1, Name=Pankaj

Apache Commons DBCP Example

If you look at above Java DataSource factory class, there are two major issues with it.

  1. The factory class methods to create the MySQL and Oracle DataSource are tightly coupled with respective driver API. If we want to remove support for Oracle database in future or want to add some other database support, it will require code change.
  2. Most of the code to get the MySQL and Oracle DataSource is similar, the only different is the implementation class that we are using.

Apache Commons DBCP API helps us in getting rid of these issues by providing Java DataSource implementation that works as an abstraction layer between our program and different JDBC drivers.

Apache DBCP library depends on Commons Pool library, so make sure they both are in the build path as shown in the image.

Here is the DataSource factory class using BasicDataSource that is the simple implementation of DataSource.


package com.journaldev.jdbc.datasource;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;

public class DBCPDataSourceFactory {

	public static DataSource getDataSource(String dbType){
		Properties props = new Properties();
		FileInputStream fis = null;
		BasicDataSource ds = new BasicDataSource();
		
		try {
			fis = new FileInputStream("db.properties");
			props.load(fis);
		}catch(IOException e){
			e.printStackTrace();
			return null;
		}
		if("mysql".equals(dbType)){
			ds.setDriverClassName(props.getProperty("MYSQL_DB_DRIVER_CLASS"));
            ds.setUrl(props.getProperty("MYSQL_DB_URL"));
            ds.setUsername(props.getProperty("MYSQL_DB_USERNAME"));
            ds.setPassword(props.getProperty("MYSQL_DB_PASSWORD"));
		}else if("oracle".equals(dbType)){
			ds.setDriverClassName(props.getProperty("ORACLE_DB_DRIVER_CLASS"));
            ds.setUrl(props.getProperty("ORACLE_DB_URL"));
            ds.setUsername(props.getProperty("ORACLE_DB_USERNAME"));
            ds.setPassword(props.getProperty("ORACLE_DB_PASSWORD"));
		}else{
			return null;
		}
		
		return ds;
	}
}

As you can see that depending on user input, either MySQL or Oracle DataSource is created. If you are supporting only one database in the application then you don’t even need these logic. Just change the properties and you can switch from one database server to another. The key point through which Apache DBCP provide abstraction is setDriverClassName() method.

Here is the client program using above factory method to get different types of connection.


package com.journaldev.jdbc.datasource;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.sql.DataSource;

public class ApacheCommonsDBCPTest {

	public static void main(String[] args) {
		testDBCPDataSource("mysql");
		System.out.println("**********");
		testDBCPDataSource("oracle");
	}

	private static void testDBCPDataSource(String dbType) {
		DataSource ds = DBCPDataSourceFactory.getDataSource(dbType);
		
		Connection con = null;
		Statement stmt = null;
		ResultSet rs = null;
		try {
			con = ds.getConnection();
			stmt = con.createStatement();
			rs = stmt.executeQuery("select empid, name from Employee");
			while(rs.next()){
				System.out.println("Employee ID="+rs.getInt("empid")+", Name="+rs.getString("name"));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
				try {
					if(rs != null) rs.close();
					if(stmt != null) stmt.close();
					if(con != null) con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
		}
	}

}

When you run above program, the output will be same as earlier program.

If you look at the Java JDBC DataSource and above usage, it can be done with normal DriverManager too. The major benefit of Java DataSource is when it’s used within a Context and with JNDI.

With simple configurations we can create a Database Connection Pool that is maintained by the Container itself. Most of the servlet containers such as Tomcat and JBoss provide it’s own Java DataSource implementation and all we need is to configure it through simple XML based configurations and then use JNDI context lookup to get the Java DataSource and work with it. This helps us by taking care of connection pooling and management from our application side to server side and thus giving us more time to write business logic for the application.

In next tutorial, we will learn how we can configure DataSource in Tomcat Container and use it in Web Application.

Comments

  1. Vishwas Atrey says:

    Can you show other features of org.apache.commons.dbcp in jdbc and hibernate?
    That would be really useful. Your tutorials are really great.
    Thank you

  2. alex says:

    hi, please help.

    RESULT:
    Motor de BD mysql
    URL TOMADA =jdbc:mysql://lxbd01:3306/Prueba1
    se va a usar la conexion com.mysql.cj.jdbc.MysqlDataSource@368102c8
    java.sql.SQLException: Access denied for user ‘USERAPP’@’192.168.1.8’ (using password: YES)
    **********
    at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)

    WHEN properties is #mysql DB properties
    MYSQL_DB_DRIVER_CLASS=com.mysql.jdbc.Driver
    MYSQL_DB_URL=jdbc:mysql://lxbd01:3306/Prueba1
    MYSQL_DB_USERNAME=USERAPP

  3. Daniel says:

    Thanks.. This article is what I was looking for!

  4. HANGNKM says:

    where will db.properties be placed? please show me the structure of this project

    1. Pankaj says:

      Check the image, it’s on Eclipse project root directory.

  5. Hiten says:

    A simple way to use the DatasourceFactory is to be use the below code

    /* Invoke the database */
    InitialContext jndiEnc = new InitialContext();
    DataSource ds = (DataSource) jndiEnc.lookup(“java:comp/env/jdbc/DBASE”);
    conn = ds.getConnection();

    /* The Connection object received is an instance of PooledConnection.
    Following line converts PooledConnection to OracleConnection. */
    oracleconn = (OracleConnection) (Connection) ((PooledConnection) conn).getConnection();

    You can find the detailed configuration to be done in the following post.

    http://tenthsense.blogspot.in/2016/12/improve-jdbc-oracle-database.html

    1. bellis says:

      Thank you!

  6. Ath J says:

    Good tutorial ,But is connection pooling being used in the above examples ??

    1. dave Johnson says:

      I also want to know the answer for this question. Pankaj please give the answer. Thankss!

      I know that if you use dbcp’s BasicDataSource instead of OracleDataSource or MysqlDataSource, you are getting connection pool already without further ado.

      1. Pankaj says:

        In above examples we are creating direct connection and not using connection pool.

  7. Ashutosh Kumar Dwivedi says:

    Getting this error ….
    java.sql.SQLException: Access denied for user ”@’localhost’ (using password: YES)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:870)
    at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1659)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1206)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)
    at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:790)
    at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:44)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)
    at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:422)
    at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:134)
    at com.mysql.jdbc.jdbc2.optional.MysqlDataSource.getConnection(MysqlDataSource.java:105)
    at com.ashu.dbcp.TestDataSource.testDataSource(TestDataSource.java:28)
    at com.ashu.dbcp.TestDataSource.main(TestDataSource.java:71)

    1. Pankaj says:

      user name is empty, please check. Also check if you are able to connect using mysql command line.

  8. Dan says:

    Great tutorial! Thanks!

  9. venkat says:

    awesomw pankaj…. 🙂

  10. Bapan Dhali says:

    Could you please tell me why I am getting that type of exception when I run the program. Exception given below.

    package com.java.test;

    import java.sql.Connection;

    import java.sql.DriverManager;

    import java.sql.SQLException;

    public class DatabaseTest {

    public static void main(String[] args) {

    try {

    Class.forName(“oracle.jdbc.OracleDriver”);

    Connection con = DriverManager.getConnection(“jdbc:oracle:thin:@//localhost:1521:orcle”,”system”,”Infy1234″);

    System.out.println(“connected..”+con);

    } catch (ClassNotFoundException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    } catch (SQLException e) {

    // TODO Auto-generated catch block

    e.printStackTrace();

    }

    }

    }

    ======================

    Exception:

    java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)

    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)

    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)

    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:414)

    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)

    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)

    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at com.infy.DatabaseTest.main(DatabaseTest.java:11)

    1. Pankaj says:

      Seems like your Database connection is not working properly. Please check user, password settings.

  11. Shifar says:

    Listen please,

    I’ve read this article and an obviously it’s working perfectly. but i’ve a doubt about Connection pooling. What is the difference between this method and the method available in this link : https://www.mulesoft.com/tcat/tomcat-mysql ? Which one is better method ?

    1. Pankaj says:

      Best option is to use server for creating connection pool and then use it in our application by getting connection from pool using JNDI.

      1. DK says:

        I am looking at exackly that, can you please explain how I can do that. I have created a datasource in Jboss AS 7 and have given it a JNDI name java:/myOwndatasource. How do lookup for this datasource in my application.

  12. Ravi Kant Gaur says:

    Hi
    I am using apache common dbcp 1.2.2 jar to create the database datasource in my project where database side we have upgraded the database Oracle 11.2.0.4.1 to Oracle 11.2.0.4.5.
    below is the my code:
    where

    1. driver=oracle.jdbc.driver.OracleDriver
    2. url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=oramtbdocq.qs2x.vwg)(PORT=1560)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=mtbdocq.qs2x.vwg)))
    3. initialsize=10
    4. maxidle=10
    5. maxactive=10

    we are using ojdbc7.jar since my jdk is 1.7

    **Code 1:** *Trying to make jdbc connection by using dbcp 1.2.2 jar*

    try{
    org.apache.commons.dbcp.BasicDataSource dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver);
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setInitialSize(initialsize);
    dataSource.setMaxIdle(maxidle);
    dataSource.setMaxActive(maxactive);
    basicDataSourceCon =dataSource.getConnection();
    System.out.println(“\n basicDataSourceCon ::”+basicDataSourceCon);
    System.out.println(“\n\n<<<<<<>>>>>\n\n”);
    }catch(Exception e2){
    System.out.println(“\n <<<<<<<<<<<>>>>>>>>>>>>>> ::”);
    e2.printStackTrace(); }

    **Exception:**
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1225)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:880)
    at com.emc.xcp.bam.bamserver.listener.BamContextLoaderListener.jdbctestConnection(BamContextLoaderListener.java:265)
    at com.emc.xcp.bam.bamserver.listener.BamContextLoaderListener.contextInitialized(BamContextLoaderListener.java:92)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1114)
    at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1673)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
    Caused by: java.sql.SQLException: Io exception: Oracle Error ORA-12650
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:257)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:389)
    at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:454)
    at oracle.jdbc.driver.T4CConnection.(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:802)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:294)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1247)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1221)
    … 17 more

    **But when I am using the simple jdbc connection it is going fine.**
    **Code 2:** *Simple jdbc connection which is going fine.*
    try{

    Properties props=new Properties();
    props.put(“user”, username);
    props.put(“password”, password);
    props.put(“maxIdle”, maxidle);
    props.put(“maxActive”, maxactive);
    props.put(“initialSize”, initialsize);

    Class.forName(driver);
    DriverManager.getDriver(url);
    simplecon = DriverManager.getConnection(url,props); //DriverManager.getConnection(url,username,password);
    System.out.println(“\n Simple JDBC simplecon ::”+simplecon);
    System.out.println(“\n\n<<<<<<>>>>>\n\n”);
    }catch(Exception e1){
    System.out.println(“\n <<<<<<<<<<<>>>>>>>>>>>>>> ::”);
    e1.printStackTrace();
    }

    Any Idea? What could be the root cause.

    Thanks in advance.

    1. Pankaj says:

      I am not sure what is wrong by looking at your code snippet, if you can share that with me then I might have a look at it.

  13. LingaMoorthy Reddy says:

    Hello Sir,

    I want crate a table in oracle using remote desktop connection then I want write java code for import that data from oracle to mysql in my system. Please help me to write a code for this issue. Really I don’t know how to write a code for it. Kindly, request you to help me in this code.

    Thnaks
    N LingaMoorthy Reddy

    1. Pankaj says:

      I have not worked on anything like this, please use Google. I am sure you will find something to get started.

  14. marcos says:

    Can this talk to any database by just adding more jars?

    1. Pankaj says:

      Depends if the database is supported, you can check it out.

  15. sumit says:

    Why have you defined- ORACLE_DB_DRIVER_CLASS=oracle.jdbc.driver.OracleDriver in props file. We are not using it anywhere in our code?

    1. Pankaj says:

      This is to keep it configurable. We are using it to work with Oracle database using Java JDBC DataSource.

  16. jonnyhaski says:

    Hello.

    I am setting up Oracle SQLdeveloper to work with mySQL. I’ve setted up driver and login details. But have error while connecting to database

    An error was encountered performing the requested operation:
    Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet’ variable.
    Vendor code 0

    Is there any suggestions how to fix this?

    I don’t have mysql server on client machine(windows 7). Only driver and sqldeveloper installed. And I don’t want to reduce max_allowed_packet size on my debian server. I’ve read this doc http://www.ccs.neu.edu/home/kathleen/classes/cs3200/connector-j.pdf But couldn’t understand how to edit this http://clip2net.com/s/jpjkq6

    Thank you in advance.

  17. Sumit Chouksey says:

    can u please give the JDBC program for Disconnected Architecture which uses the javax.sql package

  18. Siddu says:

    Could you post RowSet interface concepts.

Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages