Oracle Jdbc Driver 10.2.0.2.0 fails to render Euro (€) when db is set to WE8MSWIN1252 encoding

We just spent a few glorious hours or so trawling the internet and writing old skool jdbc code, to discover this little beauty. Simply upgrade to 10.2.0.5 of the jdbc driver and it goes away.

Thanks to this post http://efreedom.com/Question/1-377745/Oracle-JDBC-Euro-Character we discovered our problem.

For the full details on the euro….

http://www.fileformat.info/info/unicode/char/20ac/index.htm

And if your really bored:

http://www.fileformat.info/info/unicode/char/1f47e/index.htm

Share

Install Oracle XE 10g On OS X with VMWare Fusion

Oracle HQ

Oracle don’t yet provide a native OS X installer for XE but you can install it on a virtual machine running under OS X.

I found a very detailed article here [1] but also found it quite hard to follow, so thought I would post my own experience here, referring back to that one where appropriate.

First you need VMWare Fusion

I have installed Windows XP SP 2 on there.

The installation of Fusion and XP was pretty straightforward, just point and click. Once the windows guest machine is set up, fusion should prompt you to install VMWare tools which makes the graphics look much better. It will also ask you to install McAffee anti virus (its a free 12 month trial) which I did.

According to [1], it is important to set the computer name. In my case I set this to be “winxp-guest” (right click My Computer).

Next thing is to get the networking set up correctly. You have 3 options with VMWare Fusion:

  • NAT – share the network adapter with the host machine
  • BRIDGED – VM appears to be a seperate machine to the host
  • PRIVATE – VM is only available within the host machine and not on the wider network

PRIVATE networking means your VM cannot connect to the internet, so the best option is NAT

When you change your network settings you need to renew your network config:

ipconfig /release
ipconfig /renew

You should see your IP address like this:

C:\Documents and Settings\Administrator>ipconfig /renew
Windows IP Configuration
Ethernet adapter Local Area Connection:
       Connection-specific DNS Suffix  . : localdomain
       IP Address. . . . . . . . . . . . : 192.168.xx.xxx
       Subnet Mask . . . . . . . . . . . : 255.255.255.0
       Default Gateway . . . . . . . . . : 192.168.xx.xx

In order to be able to connect to your guest machine from outside, you need to configure firewalls…

Initially, I disabled McAffee. Once I got everything working, I re-enabled Mcaffee and found that when I tried to access using SqlDeveloper it automatically asked me if I wanted to allow this program.

To setup the windows firewall, you need to go to Control Panel -> Windows Firewall -> Exceptions -> Add Port…
You’ll need to do this twice, one for http access to the admin tool (8080) and one for client access (1521 which is the default)

You also need to select Advanced -> ICMP -> Allow incoming echo request if you want to be able to ping it.

From the host:

ping 192.168.xx.xxx
64 bytes from 192.168.xx.xxx: icmp_seq=0 ttl=128 time=0.290 ms
64 bytes from 192.168.xx.xxx: icmp_seq=1 ttl=128 time=0.498 ms

You should also setup your hosts file on the host computer:

sudo vi /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
::1             localhost
fe80::1%lo0     localhost
192.168.xx.xxx winxp-guest winxp-guest.localdomain

The localdomain part I found out from installing apache. Note, I also ran “Network ID” wizard from the My Computer-> Computer Name screen, not sure if that made a difference.

Now you can ping winxp-guest

To check that everything is in order, I installed apache on the guest

I picked httpd-2.2.15-win32-x86-no_ssl.msi and within a few moments I can navigate to http://winxp-gueston the guest machine and see an apache “It Works!” page.

I can also do this from my host machine, so networking is all good.

In the reference it mentions setting up the windows hosts file aswell on the guest machine, this is so that everything works on the guest machine with the tnsnames.ora file (it get generated to point to whatever the hostname of your machine is). It is not important to connect from the host machine.

# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host
127.0.0.1       localhost
192.168.xx.xxx winxp-guest winxp-guest.localdomain

Next install Oracle XE itself. The only thing required to enter here is a password, which you will later use to log in to the web interface with the user “SYSTEM”

Once installed, you can launch the home page and log in as SYSTEM. The first thing to do is to change “Administration->Http Access” which will allow computers outside the machine to access the admin console.

Then you can try it out using sqlplus. I found there was a mistake in the Environment PATH variable – it had referred to the bin directory as “bin” but in windows it was actually “BIN”. Changing it made it work for me.

sqlplus SYSTEM/{password}@XE
SQL> create table foo (bar number, baz varchar(255));
SQL> insert into foo VALUES (2, ‘blah’);
SQL> select * from foo;
       BAR
———-
BAZ
—————–
         2
blah
SQL> drop table foo;

Brilliant. You have an oracle database.

The connection XE is from your tnsnames.ora file which lives (in default install) at C:\oraclexe\app\oracle\product\10.2.0\server\NETWORK\ADMIN

and contains:

XE =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = winxp-guest)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = XE)
    )
  )

Notice the hostname in here. Presumably if you wanted to change this you could update this file and the computer name and your hosts file.

Next step is to try accessing from the host machine.

I used Oracle SQLDeveloper

I used a jdbc connection string of jdbc:oracle:thin:@winxp-guest:1521:xe

Note that as long as you update /etc/hosts on the host machine, you can call the computer whatever you like (e.g. oraclexe)

Something you might need to do is create a new tablespace. You can do this through the oracle administration console. Go to “home” and then SQL and you can execute sql like this:

create tablespace
 datafile ‘/ORACLEXE/ORADATA/XE/{table_space_name}/{table_space_name}.dbf’ size 500m;

References:

[1] http://blog.mclaughlinsoftware.com/how-to-configure-mac-os-x-as-an-oracle-client/

Share

Format a SQL String nicely (and simply)

After playing with regular expressions in notepad+, we were writing some tests around a SQL based query language and wanted to print out the queries nicely.

We came up with the remarkably simply yet effective use of String.replace() to create the following:


     String querystring = getSomeQueryString();
     System.out.println(queryString 
                .replaceAll("WHERE", "\\nWHERE")
                .replaceAll("AND", "\\n\\tAND")
                .replaceAll("OR", "\\n\\t\\tOR"));

Well it worked for ours, think might need some adjustment for different OR / AND structures.

Share