I, Me and Myself

Connecting to OracleXE, from JDBC.

In Technology on August 26, 2007 at 3:39 pm

I was pleasantly surprised, when I went and downloaded Oracle XE today.

It is actually just a 165mb download now, that is, if you want the version with just English Language support, only.

During installation it took about 1.6 Gigs of space, but more importantly the Oracle XE service takes only about 20mb of RAM, with a peak working set of about 100Mb on my Windows Vista.

Perfect, if you want a standard database, on your laptop!

Clearly the present Expression Edition is a completely redesigned product, compared to the one, that was launched about 2 years ago. That was over a Gig in size, and took about 300mb of memory on my Windows XP box. In fact that version of Oracle XE was just the Oracle Standard Edition with a different splash screen!

This however is smaller, less resource hungry, and is an ideal candidate to replace the MySQL development database, I have on my laptop.

Before you say hurray, Oracle XE has some restrictions. Be sure to read them here.

After you have installed XE, go ahead and unlock the HR schema.

Open up TOAD or Oracle SQL Developer, login as HR/hr and write a few queries for fun.

And if  you want to connect to Oracle using JDBC, here is the code.

    private void makeConnection()
    {
        Connection con = null;
        Statement stmnt = null;
        ResultSet rs = null;
        try
        {
            Class.forName("oracle.jdbc.driver.OracleDriver");
            con = DriverManager.getConnection("jdbc:oracle:thin:HR/hr@//localhost:1521/XE");
            stmnt = con.createStatement();
            rs = stmnt.executeQuery("Select * from Jobs");
            while (rs.next())
            {
                System.out.println(rs.getObject(2));
            }
        }
        catch (ClassNotFoundException e)
        {
            e.printStackTrace();
        }
        catch (SQLException e)
        {
            e.printStackTrace();
        }
        finally
        {
            if (con != null)
                try
                {
                    con.close();
                    stmnt.close();
                    rs.close();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
        }
    }

  1. Hey,

    Being a new Java dev, and an intern, it was an immensely helpful article. Thanks. :)