Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is part of the Java Standard Edition platform, from Oracle Corporation. JDBC standardises how to connect to a database, how to execute queries, how to navigate the result on a query, and how to execute updates in the database.
Because the JDBC only defines the standard how to operate a database from Java, each database engine will provide a connector that implements that standard.
Before starting with MySQL you need to download MySQL Connector from the download page and attach to your project or if you are using Maven structure you need to add it as a dependency.
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> </dependency>
For Oracle, you need to downloadits own driver and attach it to your project. For Maven users, add this dependency.
<dependency> <groupId>com.oracle.jdbc</groupId> <artifactId>ojdbc7</artifactId> <version>188.8.131.52</version> </dependency>
For Microsoft SQL Server you need this driver. For Maven users, you need to add it manually to the maven local repository and then to add it as a dependency.
To do this follow these steps:
- Download the driver.
- unzip all files to alocal directory.
- Go to command prompt navigate to folder where sqljdbc4.jar is located and execute thefollowing command:
mvn install:install-file -Dfile=sqljdbc4.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc4 -Dversion=6.0.7130.100 -Dpackaging=jar
If you need more info on how to add libraries to local maven repository followHow to include library into maven local repositorytutorial.
- Now you are able to add it as dependency on your pom.xml file:
<dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <version>6.0.7130.100</version> </dependency>
Download the driver and attach it to the project, or for Maven users add the dependency.
<dependency> <groupId>postgresql</groupId> <artifactId>postgresql</artifactId> <version>9.1-901-1.jdbc4</version> </dependency>
MySQL JDBC Statement and PreparedStatement
- How to connect to MySQL with JDBC driver
- How to sleep a thread in Java
- JDBC Statement vs PreparedStatement
- How to create thread pool in Java
- How to create a table using JDBC Statement
- How to insert a record using JDBC PreparedStatement
- How to select records using JDBC PreparedStatement
- How to update a record using JDBC PreparedStatement
- How to delete a record using JDBC PreparedStatement
- How to create threads in Java
MySQL Stored Procedure
MSSQL JDBC Statement and PreparedStatement
MSSQL Stored Procedure
Oracle JDBC Statement and PreparedStatement
Oracle Stored Procedure
PostgreSQL JDBC Statement and PreparedStatement
PostgreSQL Stored Procedure