Install Jdbc Driver Windows
Class.forName('org.postgresql.Driver'); However, since I am new to postgreSQL I have no idea where I should be putting this line, or if this is even correct. My question is, short of moving the jar file to this location, what do I actually need to do in order to install the JDBC driver on my postgreSQL installation? The WebLogic Server distribution includes WebLogic-supplied native libraries for each DBMS. Installing a WebLogic jdbcKona JDBC driver requires that these native libraries be available to WebLogic Server by including them in your system's PATH (Windows NT) or shared library path (UNIX), as described below. Install MySQL JDBC driver msi. Ask Question Asked 5 years, 10 months ago. Add Classpath for jdbc driver under windows 7-1. Installing mySQL for windows.
-->This section provides quickstart instructions for making a simple connection to a SQL Server database by using the Microsoft JDBC Driver for SQL Server. Before you connect to a SQL Server database, SQL Server must first be installed on either your local computer or a server, and the JDBC driver must be installed on your local computer.
Jdbc Driver Jar File
Choosing the right JAR file
The Microsoft JDBC Driver provides different Jars to be used in correspondence with your preferred Java Runtime Environment (JRE) settings, as under:
The Microsoft JDBC Driver 7.4 for SQL Server provides mssql-jdbc-7.4.1.jre8.jar, mssql-jdbc-7.4.1.jre11.jar, and mssql-jdbc-7.4.1.jre12.jar class library files.
The Microsoft JDBC Driver 7.2 for SQL Server provides mssql-jdbc-7.2.2.jre8.jar, and mssql-jdbc-7.2.2.jre11.jar class library files.
The Microsoft JDBC Driver 7.0 for SQL Server provides mssql-jdbc-7.0.0.jre8.jar, and mssql-jdbc-7.0.0.jre10.jar class library files.
The Microsoft JDBC Driver 6.4 for SQL Server provides mssql-jdbc-6.4.0.jre7.jar, mssql-jdbc-6.4.0.jre8.jar, and mssql-jdbc-6.4.0.jre9.jar class library files.
The Microsoft JDBC Driver 6.2 for SQL Server provides mssql-jdbc-6.2.2.jre7.jar, and mssql-jdbc-6.2.2.jre8.jar class library files.
The Microsoft JDBC Drivers 6.0 and 4.2 for SQL Server provide sqljdbc41.jar, and sqljdbc42.jar class library files.
The Microsoft JDBC Driver 4.1 for SQL Server provides the sqljdbc41.jar class library file.
Your choice will also determine available features. For more information about which JAR file to choose, see System requirements for the JDBC driver.
Setting the classpath
The Microsoft JDBC driver jars are not part of the Java SDK and must be included in Classpath of user application.
If using JDBC Driver 4.1 or 4.2, set the classpath to include sqljdbc41.jar or sqljdbc42.jar file from respective driver download.
If using JDBC Driver 6.2, set the classpath to include the mssql-jdbc-6.2.2.jre7.jar or mssql-jdbc-6.2.2.jre8.jar.
If using JDBC Driver 6.4, set the classpath to include the mssql-jdbc-6.4.0.jre7.jar, mssql-jdbc-6.4.0.jre8.jar, or mssql-jdbc-6.4.0.jre9.jar.
If using JDBC Driver 7.0, set the classpath to include the mssql-jdbc-7.0.0.jre8.jar or mssql-jdbc-7.0.0.jre10.jar.
If using JDBC Driver 7.2, set the classpath to include the mssql-jdbc-7.2.2.jre8.jar or mssql-jdbc-7.2.2.jre11.jar.
If using JDBC Driver 7.4, set the classpath to include the mssql-jdbc-7.4.1.jre8.jar, mssql-jdbc-7.4.1.jre11.jar, or mssql-jdbc-7.4.1.jre12.jar.
If the classpath is missing an entry for the right Jar file, an application will throw the common Class not found
exception.
For Microsoft JDBC Driver 7.4
The mssql-jdbc-7.4.1.jre8.jar, mssql-jdbc-7.4.1.jre11.jar, or mssql-jdbc-7.4.1.jre12.jar files are installed in the following locations:
The following snippet is an example of the CLASSPATH statement that is used for a Windows application:
CLASSPATH =.;C:Program FilesMicrosoft JDBC Driver 7.4 for SQL Serversqljdbc_7.4enumssql-jdbc-7.4.1.jre11.jar
The following snippet is an example of the CLASSPATH statement that is used for a Unix/Linux application:
CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_7.4/enu/mssql-jdbc-7.4.1.jre11.jar
Make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either mssql-jdbc-7.4.1.jre8.jar, mssql-jdbc-7.4.1.jre11.jar, or mssql-jdbc-7.4.1.jre12.jar.
For Microsoft JDBC Driver 7.2
The mssql-jdbc-7.2.2.jre8.jar or mssql-jdbc-7.2.2.jre11.jar files are installed in the following locations:
The following snippet is an example of the CLASSPATH statement that is used for a Windows application:
CLASSPATH =.;C:Program FilesMicrosoft JDBC Driver 7.2 for SQL Serversqljdbc_7.2enumssql-jdbc-7.2.2.jre11.jar
The following snippet is an example of the CLASSPATH statement that is used for a Unix/Linux application:
CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_7.2/enu/mssql-jdbc-7.2.2.jre11.jar
Make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either mssql-jdbc-7.2.2.jre8.jar or mssql-jdbc-7.2.2.jre11.jar.
For Microsoft JDBC Driver 7.0
The mssql-jdbc-7.0.0.jre8.jar or mssql-jdbc-7.0.0.jre10.jar files are installed in the following locations:
The following snippet is an example of the CLASSPATH statement that is used for a Windows application:
CLASSPATH =.;C:Program FilesMicrosoft JDBC Driver 7.0 for SQL Serversqljdbc_7.0enumssql-jdbc-7.0.0.jre10.jar
The following snippet is an example of the CLASSPATH statement that is used for a Unix/Linux application:
CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_7.0/enu/mssql-jdbc-7.0.0.jre10.jar
Make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either mssql-jdbc-7.0.0.jre8.jar or mssql-jdbc-7.0.0.jre10.jar.
For Microsoft JDBC Driver 6.4
The mssql-jdbc-6.4.0.jre7.jar, **mssql-jdbc-6.4.0.jre8.jar, or mssql-jdbc-6.4.0.jre9.jar files are installed in the following location:
The following snippet is an example of the CLASSPATH statement that is used for a Windows application:
CLASSPATH =.;C:Program FilesMicrosoft JDBC Driver 6.4 for SQL Serversqljdbc_6.4enumssql-jdbc-6.4.0.jre9.jar
The following snippet is an example of the CLASSPATH statement that is used for a Unix/Linux application:
CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_6.4/enu/mssql-jdbc-6.4.0.jre9.jar
Make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either mssql-jdbc-6.4.0.jre7.jar, **mssql-jdbc-6.4.0.jre8.jar, or mssql-jdbc-6.4.0.jre9.jar.
For Microsoft JDBC Driver 6.2
The mssql-jdbc-6.2.2.jre7.jar or mssql-jdbc-6.2.2.jre8.jar files are installed in the following locations:
The following snippet is an example of the CLASSPATH statement that is used for a Windows application:
CLASSPATH =.;C:Program FilesMicrosoft JDBC Driver 6.2 for SQL Serversqljdbc_6.2enumssql-jdbc-6.2.2.jre8.jar
The following snippet is an example of the CLASSPATH statement that is used for a Unix/Linux application:
CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_6.2/enu/mssql-jdbc-6.2.2.jre8.jar
Make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either mssql-jdbc-6.2.2.jre7.jar or mssql-jdbc-6.2.2.jre8.jar.
For Microsoft JDBC Driver 4.1, 4.2, and 6.0
The sqljdbc.jar file, sqljdbc4.jar file, sqljdbc41.jar, or sqljdbc42.jar file are installed in the following location:
The following snippet is an example of the CLASSPATH statement that is used for a Windows application:
CLASSPATH =.;C:Program FilesMicrosoft JDBC Driver 6.0 for SQL Serversqljdbc_4.2enusqljdbc42.jar
The following snippet is an example of the CLASSPATH statement that is used for a Unix/Linux application:
CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_4.2/enu/sqljdbc42.jar
Make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either sqljdbc.jar, sqljdbc4.jar, sqljdbc41.jar, or sqljdbc42.jar.
Note
On Windows systems, directory names longer than the 8.3 filename convention or folder names with spaces may cause problems with classpaths. If you suspect these types of issues, you should temporarily move the sqljdbc.jar file, sqljdbc4.jar file, or the sqljdbc41.jar file into a simple directory name such as C:Temp
, change the classpath, and determine whether that addresses the problem.
Applications that are run directly at the command prompt
The classpath is configured in the operating system. Append sqljdbc.jar, sqljdbc4.jar, or sqljdbc41.jar to the classpath of the system. Alternatively, you can specify the classpath on the Java command line that runs the application by using the java -classpath
option.
Applications that run in an IDE
Each IDE vendor provides a different method for setting the classpath in its IDE. Just setting the classpath in the operating system will not work. You must add sqljdbc.jar, sqljdbc4.jar, or sqljdbc41.jar to the IDE classpath.
Servlets and JSPs
Servlets and JSPs are run in a servlet/JSP engine such as Tomcat. The classpath must be set according to the servlet/JSP engine documentation. Just setting the classpath in the operating system will not work. Some servlet/JSP engines provide setup screens that you can use to set the classpath of the engine. In that situation, you must append the correct JDBC Driver JAR file to the existing engine classpath and restart the engine. In other situations, you can deploy the driver by copying sqljdbc.jar, sqljdbc4.jar, or sqljdbc41.jar to a specific directory, such as lib, during engine installation. The engine driver classpath can also be specified in an engine-specific configuration file.
Enterprise Java Beans
Enterprise Java Beans (EJB) are run in an EJB container. EJB containers are sourced from various vendors. Java applets run in a browser but are downloaded from a web server. Copy sqljdbc.jar, sqljdbc4.jar, or sqljdbc41.jar to the web server root and specify the name of the JAR file in the HTML archive tab of the applet, for example, <applet ... archive=mssql-jdbc-***.jar>
.
Making a simple connection to a database
Using the sqljdbc.jar class library, applications must first register the driver as follows:
Class.forName('com.microsoft.sqlserver.jdbc.SQLServerDriver');
When the driver is loaded, you can establish a connection by using a connection URL and the getConnection method of the DriverManager class:
Starting from JDBC API 4.0, the DriverManager.getConnection()
method is enhanced to load JDBC drivers automatically. Therefore, applications do not need to call the Class.forName
method to register or load the driver when using driver jar libraries.
When the getConnection method of the DriverManager class is called, an appropriate driver is located from the set of registered JDBC drivers. sqljdbc4.jar, sqljdbc41.jar, or sqljdbc42.jar file includes 'META-INF/services/java.sql.Driver' file, which contains the com.microsoft.sqlserver.jdbc.SQLServerDriver as a registered driver. The existing applications, which currently load the drivers by using the Class.forName method, will continue to work without modification.
Note
sqljdbc4.jar, sqljdbc41.jar, or sqljdbc42.jar class library cannot be used with older versions of the Java Runtime Environment (JRE). See System requirements for the JDBC driver for the list of JRE versions supported by the Microsoft JDBC Driver for SQL Server.
For more information about how to connect with data sources and use a connection URL, see Building the connection URL and Setting the connection properties.
See also
- JDBC Tutorial
- JDBC Examples
- JDBC Useful Resources
- Selected Reading
To start developing with JDBC, you should setup your JDBC environment by following the steps shown below. We assume that you are working on a Windows platform.
Install Java
Install J2SE Development Kit 5.0 (JDK 5.0) from Java Official Site.
Make sure following environment variables are set as described below −
JAVA_HOME: This environment variable should point to the directory where you installed the JDK, e.g. C:Program FilesJavajdk1.5.0.
CLASSPATH: This environment variable should have appropriate paths set, e.g. C:Program FilesJavajdk1.5.0_20jrelib.
PATH: This environment variable should point to appropriate JRE bin, e.g. C:Program FilesJavajre1.5.0_20bin.
It is possible you have these variable set already, but just to make sure here's how to check.
Go to the control panel and double-click on System. If you are a Windows XP user, it is possible you have to open Performance and Maintenance before you will see the System icon.
Go to the Advanced tab and click on the Environment Variables.
Now check if all the above mentioned variables are set properly.
You automatically get both JDBC packages java.sql and javax.sql, when you install J2SE Development Kit 5.0 (JDK 5.0).
Install Database
The most important thing you will need, of course is an actual running database with a table that you can query and modify.
Install a database that is most suitable for you. You can have plenty of choices and most common are −
MySQL DB: MySQL is an open source database. You can download it from MySQL Official Site. We recommend downloading the full Windows installation.
In addition, download and install MySQL Administrator as well as MySQL Query Browser. These are GUI based tools that will make your development much easier.
Finally, download and unzip MySQL Connector/J (the MySQL JDBC driver) in a convenient directory. For the purpose of this tutorial we will assume that you have installed the driver at C:Program FilesMySQLmysql-connector-java-5.1.8.
Accordingly, set CLASSPATH variable to C:Program FilesMySQLmysql-connector-java-5.1.8mysql-connector-java-5.1.8-bin.jar. Your driver version may vary based on your installation.
PostgreSQL DB: PostgreSQL is an open source database. You can download it from PostgreSQL Official Site.
The Postgres installation contains a GUI based administrative tool called pgAdmin III. JDBC drivers are also included as part of the installation.
Oracle DB: Oracle DB is a commercial database sold by Oracle . We assume that you have the necessary distribution media to install it.
Oracle installation includes a GUI based administrative tool called Enterprise Manager. JDBC drivers are also included as a part of the installation.
Install Database Drivers
The latest JDK includes a JDBC-ODBC Bridge driver that makes most Open Database Connectivity (ODBC) drivers available to programmers using the JDBC API.
Now a days, most of the Database vendors are supplying appropriate JDBC drivers along with Database installation. So, you should not worry about this part.
Set Database Credential
For this tutorial we are going to use MySQL database. When you install any of the above database, its administrator ID is set to root and gives provision to set a password of your choice.
Using root ID and password you can either create another user ID and password, or you can use root ID and password for your JDBC application.
There are various database operations like database creation and deletion, which would need administrator ID and password.
For rest of the JDBC tutorial, we would use MySQL Database with username as ID and password as password.
If you do not have sufficient privilege to create new users, then you can ask your Database Administrator (DBA) to create a user ID and password for you.
Create Database
To create the EMP database, use the following steps −
Step 1
Open a Command Prompt and change to the installation directory as follows −
Note: The path to mysqld.exe may vary depending on the install location of MySQL on your system. You can also check documentation on how to start and stop your database server.
Step 2
Start the database server by executing the following command, if it is already not running.
Step 3
Create the EMP database by executing the following command −
Create Table
To create the Employees table in EMP database, use the following steps −
Step 1
Open a Command Prompt and change to the installation directory as follows −
Step 2
Login to the database as follows −
Step 3
Install Jdbc Driver Windows 10
Create the table Employee as follows −
Create Data Records
Finally you create few records in Employee table as follows −
For a complete understanding on MySQL database, study the MySQL Tutorial.
Install Sql Jdbc Driver Windows
Now you are ready to start experimenting with JDBC. Next chapter gives you a sample example on JDBC Programming.