Random Oracle notes – creating a user and granting privileges

As a developer I normally get to work with Oracle in a db that’s already been set up, my user is set up with the correct permissions etc. I’ve been working with Oracle Express installed on my own machine, and had to do a few basic steps to get up and running.

Log on as system to create new users and grant privs:

sqlplus system/yourpassword
create user youruser identified by yourpassword;
grant connect to youruser;
grant resource to youruser; -- grants a bunch of normal privs, select, insert, delete etc

Logon as sysdba to grant execute on DBMS_SESSION:

sqlplus system/yourpassword as sysdba
grant execute on DBMS_SESSION to youruser;

Installing Java on OS X Lion

I’m sure there’s plenty of posts about this already, but I just upgraded to Mac OS X Lion today and it seems Java is not preinstalled. When you first attempt to launch a Java app though, Software Update launches and downloads a Java 6 JVM for you. Very nice.

Spring Roo, Maven and Oracle JDBC drivers

Oracle JDBC drivers are not freely available in any public Maven repos. Per the Spring Roo docs, if you have an Oracle product installed (presumably you do if you’re trying to connect to it), you can install the provided JDBC driver into your local Maven repo for your code to build successfully.

Using Roo 1.1.5, setting up my persistence with:

persistence setup --provider HIBERNATE --database ORACLE --databaseName XE

Resulted in this dependency added to my pom.xml:

	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc14</artifactId>
		<version>10.2.0.2</version>
		<classifier />
	</dependency>

I’m using Oracle Express 11.2.2.0 on my machine, and my JDBC driver installed with the product is here:

C:oraclexeapporacleproduct11.2.0serverjdbclibojdbc6.jar

So using the Maven install command, I can copy this file into my local repo like this:

mvn install:install-file 
    -Dfile=ojdbc6.jar 
    -DgroupId=com.oracle 
    -DartifactId=ojdbc6 
    -Dversion=11.2.0.2.0 
    -Dpackaging=jar 
    -DgeneratePom=true

And then update my jar dependency in my pom.xml to match the version of the jar that I have:

	<dependency>
		<groupId>com.oracle</groupId>
		<artifactId>ojdbc14</artifactId>
		<version>11.2.0.2.0</version>
		<classifier />
	</dependency>

Configuring Oracle Express 11g on a development machine

If you install Oracle Express 11g on laptop running Windows that is normally part of a domain and then try and run that machine elsewhere connected to a different network than normal, you may need to tweak the hostname value in your tns confiig files.

For example, my work laptop has a domain name set which is specific to my work network. When running from home and connected to the internet I’m not part of this domain, and this seems to mess with your tns config.

Browse to this location (or similar):

C:oraclexeapporacleproduct11.2.0servernetworkADMIN

Edit each of the .ora files in this location and replace your fully qualified hostname  and domain name for the HOST property to be just 127.0.0.1. I’m not sure if this means your listener is no longer listening for connections outside of your machine, but if this is a development machine this doesn’t matter.

Stop and restart your database (XE is the default for Oracle Express), and you should be good to go.

tnsping XE should now respond with OK.