Insert into EMPLOYEE (EMPID,NAME) values (5,'Kumar') Insert into EMPLOYEE (EMPID,NAME) values (10,'Pankaj') 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. Our final project will look like below image.īefore we get into our example programs, we need some database setup with table and sample data.
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. Caching of PreparedStatement for faster processing.Some of the other common features provided by these JDBC DataSource implementation classes are
These implementation classes provide methods through which we can provide database server details with user credentials. For example MySQL JDBC Driver provides basic implementation of DataSource interface with 2.optional.MysqlDataSource class and Oracle database driver implements it with class. It is the responsibility of different Database vendors to provide different kinds of implementation of DataSource interface. 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 is the preferred approach if you are looking for any of these features in your application. 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.