<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d11356004\x26blogName\x3dxception\x26publishMode\x3dPUBLISH_MODE_BLOGSPOT\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttps://openrent.blogspot.com/search\x26blogLocale\x3den_US\x26v\x3d2\x26homepageUrl\x3dhttp://openrent.blogspot.com/\x26vt\x3d-4655156434419967503', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Test a JDBC connection to Oracle database

Many tools use JDBC to talk SQL to a database server. To verify your Oracle database's ability to respond to JDBC calls, compile the following small Java program into a file called JdbcCheckup.java.

// import the Oracle JDBC drivers
import oracle.jdbc.pool.OracleDataSource;

// You need to import the java.sql package to use JDBC
import java.sql.*;

// We import java.io to be able to read from the command line
import java.io.*;

class JdbcCheckup
{
public static void main (String args [])
throws SQLException, IOException
{

// Create an OracleDataSource and set URL
OracleDataSource ods = new OracleDataSource();
ods.setURL("jdbc:oracle:thin:system/apodevs@ausy01lo221:1525:apodevs");

System.out.print ("Connecting to the database...");
System.out.flush ();

// Connect to the database

System.out.println ("Connecting...");
Connection conn = ods.getConnection();

System.out.println ("connected.");

System.out.println ("Your JDBC configuration is correct.");

// Close the connection
conn.close();
}
}

Before this program will compile, you need three things:

1) Oracle credentials:
The name of the database instance, the port it is listening on, the system account password, and the Oracle server name. These variables need to be placed in the JDBC connection string URL in the Java code. The syntax of a JDBC URL for Oracle is:

jdbc:oracle:thin:system/@::

In practice, it might look like this:
jdbc:oracle:thin:system/apodevs@ausy01lo221:1525:apodevs

2) You will need to be running a JDK on the machine where you will be running this Java code. Any version will do.

3) Download the Oracle thin JDBC driver called "classes12.jar" from Oracle's website:
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html

Once downloaded, place the JAR file in the jre|lib|ext directory of your installed JDK.

On Linux, place the JAR file in: /usr/java/jdk1.5.0_07/jre/lib/ext/
On Windows, place the JAR file in: C:\Program Files\Java\jdk1.6.0\jre\lib\ext

Now compile the .java file into a working class file: javac JdbcCheckup.java

Once compiled, you can run the program using the "java JdbcCheckup" command.