Jason’s Ranting & Raving

Those who don’t read have no advantage over those who can’t.

Mounting a Synology drive on Ubuntu Linux

Posted by jaystile on April 26, 2013

I was having a little trouble mounting my Synology network drive as described on the wiki. This is was on a clean installation of Ubuntu Linux 12.10.

These are the steps I took to figure out what was going on. First I had to find the IP address of the drive on my network. So, I downloaded nmap and then scanned my local network.

sudo apt-get install nmap
nmap -O 192.168.1.0/24

I found I was have troulbe with just using nfs as I had to use a username and password to connect to the shared drive. I found that using cifs worked for me. I installed it and then tried mounting the drive and it worked! Then I unmounted because I didn’t want to have to do this every time I wanted to access the drive.

sudo mkdir -p /mnt/synology
mount -t cifs -o username=MYUSER,password=***** //192.168.1.109/share /mnt/synology
mount -a
ls -la /mnt/synology
umount /mnt/synology

I decided I wanted a little more permanent solution. So I created incorporated the ‘Basic Method’ steps from the synology wiki. I edited the /etc/fstab with the following:

//192.168.1.109/share /mnt/synology cifs user,uid=yourusername,gid=users,rw,suid,credentials=/etc/cifspwd 0 0

Next was to create to the cifspw file.

sudo su -
echo username=yourusername > /etc/cifspwd
echo password=yourpassword >> /etc/cifspwd
chmod 0600 /etc/cifspwd
mount -a
ls -la /mnt/synology

I hope that works for you!

Update!
I built a new PC and had to try something new as my original instructions didn’t work for the fstab and creditials file.
I ran the command

 sudo su -
 dmesg | tail

I noted that there was an error: CIFS VFS: No username specified. After a quick google search some nice person posted a solution. However, it was a touch out of date as the package smbfs was retired and cifs-utils was the recommended package offered by apt-get.

sudo apt-get install cifs-utils

After a restart my mounts came back up correctly,.

Posted in Programming, Solutions | 3 Comments »

Roulette Betting Strategy Analysis

Posted by jaystile on June 13, 2011

My friend was speaking with me about a positive progression betting strategy that he had used successfully. Me being the analytical person that I am began obsessing about it. Why did I obsess about it? It was because I could not see how it would fail. It’s evident now but not before I modeled the strategy. Enjoy my analysis on some common strategies.

The Model
I wrote my own Roulette simulator in java. Each ‘player’ uses a specific strategy. Each player started with $300. The minimum bet on the table is $5. A maximum bet was not enforced. 100 Sessions of 100 spins were completed for the players.

The Positive Progression
There are streaks in gambling. One wishes to bet the minimum when on a losing streak and bet the maximum on a winning streak. The issue with this strategy is that those positive streaks don’t seem to come frequent enough. Each time the player wins they add one betting increment ($5) to their original bet. Once a streak of three or better comes along is when the player starts to profit.

Basic Positive Progression (-20.5%)
The first ‘flavor’ is what I’m calling the ‘Basic Positive Progression’. The player bet on black and each time they won they added one increment. When they lost they started over at the first increment.

Hedged Positive Progression (-40.2%)
If it works for betting black, it’s got to work just as well for betting black and red at the same time! The theory behind this strategy is that if the spins go back and forth between red and black the player can’wait it out’ for a streak. The same theory applies as before but executing the strategy on both red and black.

First Dozen – Positive Progression (-19.5%)
You know what is better than a streak paying you 1:1? A streak paying 2:1. This is the same Positive Progression scenario as before, but using the ‘First Dozen’ bet.

Martingale (-45.1%)
The Martingale strategy is fairly straight forward. This strategy involves the player doubling their bet until they win. Then they go back to the first increment. It is common to lose all your cash or to reach the table limit causing a giant loss.

Fibonacci (-19.7%)
This strategy involves using the Fibonacci sequence to manage the player’s bets. Each time the player wins they go back two steps to the left along the sequence. Every time they lose they move one forward to the right in the sequence. The sequence looks like this 1, 1, 2, 3, 5, 8 …

First Dozen Fibonacci (-26.1%)
Same as above but using the ‘First Dozen’ bet instead of ‘Black’.

Fibonacci Positive Progression (-11.2%)
As I was experimenting played with a positive progression strategy using the Fibonacci sequence. That means every time you win you increase the number of bet increments to the appropriate number. When you lose you start over at the first number in the sequence. I was pleasantly surprised to see the result had bested all the other strategies.

First Dozen – Fibonacci Positive Progression (-08.9%)
Then I tried with a result that pays 2:1. The numbers gave me a better result, but I am not sure why. More investigation is required.

Summary
If you are going to play Roulette just keep it in mind that you’re going to lose money. Some strategies have you lose it slower than others. You might want to consider using the First Dozen – Fibonacci Positive Progression’.

Posted in Programming | Leave a Comment »

Programming: Android emulator launch from eclipse

Posted by jaystile on September 27, 2010

There are some quirks launching the Android emulator from Eclipse. Work has started on my first Android application, and I kept running into ‘oddness’. I would see errors like this:

06:57:10,094 INFO  [main] Main  - launchFile: C:\workspace\android\.metadata\.plugins\org.eclipse.wst.xsl.jaxp.launching\launch\launch.xml
06:57:10,141 FATAL [main] Main  - No embedded stylesheet instruction for file: file:/C:/workspace/android/tmpproj/res/layout/main.xml
org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embedded stylesheet instruction for file: file:/C:/workspace/android/tmpproj/res/layout/main.xml
	at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:225)
	at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:186)
	at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:73)
Caused by: org.eclipse.wst.xsl.jaxp.debug.invoker.TransformationException: No embedded stylesheet instruction for file: file:/C:/workspace/android/tmpproj/res/layout/main.xml
	at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.transform(JAXPSAXProcessorInvoker.java:214)
	... 2 more

Then a main.out.xml was getting created and it only happened sometimes. Those *.out files need to be removed. Confusion set in.

It turns out that I was clicking the ‘Run’ button while my main.xml file was selected. This makes eclipse try and do something other than launch my Android app. You need to actually select Run -> Run Configurations -> to get it to launch. 45 minutes of my life are gone!

Posted in Uncategorized | 1 Comment »

Programming: Android setup for Ubuntu

Posted by jaystile on September 27, 2010

Android Setup
I’ve been kicking the idea around of developing some Android applications. This blog post is about setting up that initial environment.

After a quick google search, I found the Android developer page. Downloaded the Linux (i386) SDK. I was thinking that I might want to develop on Windows, but I already had a VirtualBox running Ubuntu 10.04 with the Required Eclipse and JDK. I browsed the System Retirements page http://developer.android.com/sdk/requirements.html, and it looks the VM (Virtual Machine) will be just fine.

Preconfiguration
Java development downloads go to into the /opt directory on this linux VM. Softlinks are used to help maintain version of the software.

/opt/ant/latest → /opt/app/apache-ant-1.8.1
/opt/java/latest → /opt/java/jdk1.6.0_21
/opt/eclipse/latest →/opt/eclipse/eclipse-jee-helios

The ~/.bashrc file gets updated to add variables to these locations and then export the $PATH so you can execute them on the command line.

JAVA_HOME=/opt/java/latest
ANT_HOME=/opt/ant/latest
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH

Download the Android SDK

$ mkdir /opt/android/
$ wget http://dl.google.com/android/android-sdk_r07-linux_x86.tgz
$ tar zxvf android-sdk_r07-linux_x86.tgz
$ mv android-sdk-linux_x86 android-sdk-linux_x86-0.9.8 
$ ln -s android-sdk-linux_x86-0.9.8/ latest

ADT Plugin v 0.9.8
The Eclipse workspace has been setup to use /opt/workspace/android. Eclipse then needed to include the ADT plug-in . Add the site: https://dl-ssl.google.com/android/eclipse/ to Eclipse after selection Help → Install Software.

Install SDK Tools r7 into your SDK
The link describes adding new tools into your sdk http://developer.android.com/sdk/adding-components.html#UpdatingComponents .

Launch the android manager.

$ /opt/android/latest/tools/android

It looks like the Android SDK Tool revision 7 was already there! Moving on.
Odd
I got a pop-up from the Plug-in asking to enable statistics usage. But it was ‘unclickable’. So it’s just hanging out there now, so I’ll have to kill it from the command line. I could tell if it came from the Android manager or the ADT eclipse plugin.

First Project
Used Eclipse to try and create a new Android Project. This failed because an SDK was not defined.
Register SDK with Eclipse
Window → Preferences → Android
SDK Location: /opt/android/latest
Apply
Error
Failed to get the adb version: Cannot run program “/opt/android/latest/tools/adb”: java.io.IOException:error=2, No such file or directory.
That is very odd. The file is navigable from the command line. However, when trying to execute it from the command line like ./adb, the bash: ./adb: No such file or directory error occurs.
Attempting to restart (and kill that pop-up that is still hanging around).

$ /opt/android/latest/tools/android

Install packages
Installed Packages → Android SDK Tools, revision 7. Clicked update all and selected all recommended downloads.
Then removed all obsolete packages.

Try Again – With Galileo
Downloaded Eclipse JEE Galileo, I heard rumor through the grapevine that ADT Plugin did not play nice with Helios.
This still did not resolve the original issue of the adb not working.

Add the site: https://dl-ssl.google.com/android/eclipse/ to Eclipse after selection Help → Install Software. In this instance, I made it to the license agreement. However, when selecting the radio, “I agree” and scrolling down to the bottom of the license window, the ‘Finish’ button was never enabled. Thank you Mylyn for having 9 things to agree to when all I’m trying to is NOT add your plug in. It is my professional opinion that Eclipse with JEE comes with way too many plug-ins that do not have value add. Eclipse is pretty stable, but the plug-in developers really need to get on the ball. I keep running into resource hogs or plug-ins that don’t do their job very well. Have you seen the GIT plug-in? It doesn’t even come close to mapping what you can do on the command line. Going to get Eclipse just for Java to minimize plug-ins to see if I can get this to install.

Try Again – With Galileo sans JEE garbage.
Installed the basic Eclipse IDE for Java Developers. There are noticably less plug-ins install that might collide. But Mylyn is still there. Let’s see how it goes. Oh look at that! It appears that I am in the same situation. Here are the list of things to agree to:

Android DDMS
Android Development Tools
Mylyn Bridge: Eclipse IDE
Mylyn Bridge: Java Development
Mylyn Bridge: Team Support
Mylyn Connector: Bugzilla
Mylyn Task List (Required)
Mylyn Task-Focused Interface (Recommended)
Mylyn WikiText

Let’s see if my outcome is any different this time. I’ll scroll to the bottom of each agree and check I accept. Wow! Different behavior! The ‘Finish’ button was able to be clicked. Joyous happy day.

Back on track – Setup the SDK
Window → Preferences → Android
SDK Location: /opt/android/latest
Apply

Configure the SDK
Eclipse → Window → Android SDK and AVD Manager
Something weird happened again.
After selecting the option above I received and error. [2010-09-17 06:12:09 – adb]Failed to get the adb version: Cannot run program “/opt/android/latest/tools/adb”: java.io.IOException: error=2, No such file or directory
After selecting it a second time, the application launched.
Android SDK and AVD Manager (ASAM) → Installed Packages → Update All…
Now ‘Delete…’ any obsolete packages.

I got another error saying that there are packages dependent on adb, but it isn’t running. I think the 0.9.8 SKD might be fubar. After more research, there is a problem with Ubuntu 64bit (which I’m running). It looks like some 32bit libraries need to be installed. There was nothing explicit on the Android SDK site, but after more searching I found references to the 32 bit libraries under an Ubuntu forum. Then I found a matching troubleshooting article on the SDK site.

$ sudo apt-get install ia32-libs
$ /opt/android/latest/tools/adb 

Yay! ADB now does something! That was the root of my problem. Now everything is right with the world. Two hours later my quest continues.

Ubuntu Linux 13.10 64-bit
The error ‘bash: ./adb: No such file or directory’ came back. But this time ‘install ia32-libs’ did not work. However, this seemed to do the trick:

$ sudo apt-get install libc6:i386 libstdc++6:i386

Hello World
Follow the instructions from the Android Site. http://developer.android.com/resources/tutorials/hello-world.html
After the errors before, getting the Hello, Android app running was a piece of cake. That emulator is pretty cool. Then I said, f@#$ it, and I set it up to run on my windows environment.

Posted in Programming | Tagged: , | 1 Comment »

Programming: Rails with Postgres – Couldn’t create database

Posted by jaystile on August 31, 2010

Hello internet community! I wanted to share something with you that you may encounter. I was setting up a postgres database and trying to use rake db:create to create the sample database from the getting started tutorial.

I kept getting an error like:

Read error message: FATAL: Ident authentication failed for user "blog_development
...
Couldn't create database for {"encoding"=>"unicode", "username"=>"blog_development", "adapter"=>"postgresql", "database"=>"blog_development", "pool"=>5, "password"=>"tmppass"}

The default Ubuntu Postgres installation requires both a system user and a database user with matching user IDs. It turns out I had to change a setting in postgres to allow connections from just database users.

vi /etc/postgresql/8.4/main/pg_hba.conf
Change the line
local all all ident
to
local all all md5

Note: You cannot have two of the same defined combinations. The first once wins, when I had put “local all all ident” followed by “local all all md5” the second didn’t get defined. That caused me a couple of hours of heartache.

Posted in Programming | Tagged: , , | 1 Comment »

Book Review: SuperFreakonomics by Levitt & Dubner

Posted by jaystile on August 15, 2010

SuperFreakonomics

My friend from work loaned me SuperFreakonomics by Steven D. Levitt and Stephen J. Dubner. Thanks buddy! I was really looking forward to reading it. Before I get to the review, I just wanted to point out that I was so astounded by Freakonomics that I pre-ordered SuperFreakonomics for another friend that loaned me the original Freakonomics.

I only have this to say, “I LOVE FREAKONOMICS!” The process of bringing economic research techniques to areas other than finance produce interesting results. If you’ve never read this type of book, you will be pleasantly surprised. Freakonomics investigates human behavior and try and unravel the reasons why people behave the way they do. They break down the behavior and find the incentives. I’m not going to go on too much, but I love it when people break down the conventional wisdom. While most people I’ve chatted with ranked SuperFreakonomics higher than Freakonomics, I would disagree. You can read my review on Freakonomics here.

There is only about 200 pages of content in the book and I read through it over the weekend. Lots of fun and worth your time. Enjoy!

Posted in Book Review | Tagged: , , , | Leave a Comment »

Setting up Eclipse with Windows 7 issues

Posted by jaystile on June 22, 2010

I’ve bought myself a new PC which came with Windows 7. I’ve been running versions of Ubuntu on old hardware since version 6.04 and I thought I’d give the new Windows a test drive. At work we run on linux distros so this is almost a new experience for me. My friend really likes Windows 7 and to be honest I was getting a little sick and tired of external hardware not working. Specifically my webcam (which Logitech doesn’t for Windows 7 for some damn reason, I’m done doing buying anything from them) and the scanner my other friend let me borrow.

I’m working on a few side development tasks on my own. I program a lot of java so I went through and installed the latest JDK and tried to find where in the heck you set the environment variables. But I got that resolved. Next, I go and download Eclipse. I extracted the zip file with the default Windows 7 ‘Extract’ option. When I tried to run eclipse I get a weird error about a shared library not being found.

Anyway, I went searching for the answer and it looks like the Windows 7 zip handler doesn’t handle the eclipse-jee-galileo-SR2-win32.zip very well. So, I downloaded cygwin, extracted the zip, moved the eclipse folder to /cygdrive/c/eclipse. Tried to fire up eclipse again and it failed with a permissions exception. chmod -R 755 /cygdrive/c/eclipse and I was up and running. You can color me unimpressed that Windows 7 failed to correctly extract an archive.

Posted in Programming | Tagged: | Leave a Comment »

A little scary story (for kids, I think)

Posted by jaystile on June 20, 2010

My daughter is in girl scouts. Tonight, she and her troop are having a backyard camp-out. For a few hours I helped prepare for the event by cleaning and keeping my daughters out of my wife’s hair. I grilled up some tasty burgers & hot dogs for the troop. Cleaned up vomit after someone nearly choked on an apple, changed the garbage, and was all-in-all a dutiful dad and husband. I even built a wood fire in the grill so we could roast marshmallows over the flames. The girls are around age six and I was told there would be stories before bed. I wanted to tell them a scary story, but my wife said, “NO!” Here is that unheard story.

Sarah with the long pigtails
There once was a little girl named Sarah. Her house was on a quiet street in a quiet neighborhood. Every morning, she would get up, put on one of her favorite dresses, make her bed, and brush her teeth. Then she would take out a brush and brush out the few snarls in her soft hair, gather together some pig tails and braid them. She would then tie them together with a beautiful pink ribbon. Sarah really liked making her hair look nice. Her mother would say to her, “Oh Sarah, your pigtails look so beautiful today!”

It was summertime and Sarah loved being outside. She would look for bugs under the rocks in her mom’s flower garden, lie in the grass and watch the clouds roll by, or watch the neighbor’s cat sneak up with its tail twitching and try to catch birds. Sarah enjoyed the outdoors, but it was lonely on her quiet street in her quiet neighborhood for there were no children for her to play with. One day, while Sarah was making chalk drawings on the side walk she looked up and saw another child way down at the end of the street. Sarah waved and the child waved back, but the next time Sarah looked the child was gone. The next day, Sarah was watering the plants in her mom’s flower garden. When she looked up she saw the same child from the other day standing across the street. It was a little girl about Sarah’s age. The little girl had on dirty clothes, her hair was in tangles and she didn’t smile, but she yelled across the street, “I really like your pigtails!” Sarah, yelled back “Thanks!” and the child ran away. Sarah was disappointed because she wanted to make a new friend.

A few days went past and Sarah did not see the little girl. Sarah went back to watching the cat, looking for bugs, and staring at the clouds. She fell asleep in the soft grass of the front yard. When she woke up the girl with the dirty clothes and tangled hair was standing above her. “I really like your pigtails”, she said without smiling. Sarah was startled and said, “Thanks. I’m Sarah, what’s your name?” The little girl said to her, “I like your name and I really like your pigtails.” Then she turned and ran away. Sarah called out after her, “Wait! Please come back!” but the girl with the dirty clothes and tangled hair was gone.

Weeks went by and summertime was coming to a close and Sarah forgot about the little girl with the dirty clothes and tangled hair. Sarah had been asking her mom if she could camp out in the backyard. Her mom agreed and Sarah went about setting up the tent, unrolling her sleeping bag, and settled in for the evening. She noticed a lot of different noises at night, but her mom had told her what to expect, “You’ll probably hear the hooting of an owl, the chirp of crickets, and the wind rustling the leaves.” Sarah was a little nervous with all the new sounds, but eventually she got used to them and fell fast asleep in the warm night summer air. Sometime during night she woke up. It sounded like something was by the tent so she listened closely. Yes, something was moving around the tent. She turned on her flashlight and could see the the tent being touched from the outside. Sarah was so scared that she couldn’t make a sound. Then the she heard the outer flap of the tent unzip, “ZZZZZZIIIIIIPPPPPPP”. She could see someone reaching to the inner zipper, “ZZZZZZZIIIIIIIIPPPPPPPPP”. Sarah screamed! “Shush!” Sarah’s mom said. “You’ll wake up the neighbors! I was just checking to make sure you were doing alright. I’m going to bed, good night. And no more screaming!”

Soon, Sarah settled back down, turned off her flashlight, and listened to the sound of the wind blowing through the leaves and laughed because she had been so scared. “I really like your pigtails.” someone whispered. Sarah sat up like a bolt and turned on the flashlight in an instant and screamed! Sitting in the corner was the girl with the dirty clothes and tangled hair. “I’m sorry, I didn’t mean to scare you”, she said when Sarah tried to catch her breath. “My name is Sarah too, can I stay and camp with you?” Sarah with the pigtails was scared and confused, but the dirty Sarah smiled a beautiful smile. Sarah with the pigtails calmed down and dirty Sarah starting talking with her and asked her lots of questions about herself. Sarah with the pigtails felt happy because someone was finally interested in her and wanted to be her friend. After talking for many hours the Sarahs decided to go to bed and fell asleep.

In the morning, Sarah with the pigtails woke up in the soft grass in the front yard. Confused, Sarah walked up the steps of the front porch and tried to open the door, but it was locked tight. Sarah rang the doorbell and heard the footsteps coming down the hall. The door opened and her mother looked down and said, “I’m sorry Sarah can’t come out and play, she’s grounded for screaming and waking up the neighbors last night.” “BUT MOM, IT’S ME! “, Sarah cried. As the door shut Sarah could see dirty Sarah standing in the house and she had Sarah with the pigtails hair on her head like a bad wig. “I really like your pigtails”, she whispered. The door shut and Sarah reached up and touched the top of her head and her hair was all gone.

Posted in Parenting | Tagged: , | Leave a Comment »

A Free Range Kids Conversation

Posted by jaystile on June 11, 2010

Free Range Kids by Lenore Skenazy

Free Range Kids by Lenore Skenazy


The hairstylist, Elaine, complimented me today on my very outgoing 5 year old daughter. My daughter had made the rounds after her haircut to each of the stylists. She introduced herself and made small talk while Dad was getting his hair cut. She even helped sweep up the hair and straighten the shelves.“Oh, she is so friendly!”, said Elaine

I responded with, “Yes, we don’t teach Stranger Danger in our house. We teach the girls not to go anywhere with a stranger and to stay away from stranger’s cars. But it’s OK to talk to people and even except a piece of candy.”

Elaine obviously misheard me at the point. She chimes in with, “Yeah, you should never take candy from strangers.” At this point the chit-chat changed into a lecture given by myself exhorting the values of free range children. The self reliance, problem solving, and social skills to name a few. And to point out that we should only be concerned about everyday type risks and not the 1-in-a-million type risks.

Needless to say, Elaine was unwilling to back down from her position that there is danger everywhere. Yes, I agree, danger is everywhere and one should teach children to be on the lookout and how to handle different situations. “Always wear your helmet; Look left-right-left again before crossing the street; Never go anywhere with a stranger; Put on sunblock and your hat! (We live in Colorado with 5280 less feet of atmosphere to stop those UV rays); Wear your seatbelt; Slice away from your fingers (My girls help with dinner preparation)”

With a little more (less than polite) back-and-forth, I repeated from “Free Range Kids” by Lenore Skenazy that there was not one recorded instance of a child’s candy being tampered with at Halloween. This is what transpired (and you can see where I lost my patience):

“There has never been one recorded case of someone tampering with a child’s candy”
“Oh yeah, it happened to my brother!”
“What happened?”
“Someone put a razor blade in his apple!”
“Which one of your neighbors was trying to kill your brother? Did the police come?”
“We were trick-or-treating… in another neighborhood…”
“And the first thing your brother did when he got back home after a hard night of trick-or-treating was to dive into his candy bag and say ‘I really cannot wait to eat this healthy delicious apple!’ ha-ha-ha”

Laughing at Elaine’s preposterous story earned me a lot of razor burn and deep scratches on my neck. It was totally worth it.

Posted in Parenting | Tagged: , , , | Leave a Comment »

INSERT CLOB with JDBC and Oracle Prepared Statement

Posted by jaystile on May 24, 2010

The oracle API made me crazy for about six hours. That is how long it took me before I could figure out how to do an insert that includes a clob. The key to do an insert with a clob is to use the oracle.sql.CLOB.createTemporary method. The javadoc associated with the CLOB class is very sparse and does not include any instructions.

In my scenario I was trying to do an insert with a prepared statement. The Prepared Statement has a setClob method, but it really doesn’t do you any good because you don’t have a clob object available. Most of the examples I found showed a technique of creating an empty clob object and then getting a reference to the clob and then streaming data to it. This was not going to work for me because I’m running batches of statements with thousands of inserts.

This is what worked for me. It might need a little tweaking since I’m blogging from home without my development environment, so take it with a grain of salt.

// Pseudo-code
import oracle.sql.CLOB
import java.sql.Connection
import java.sql.PreparedStatement
...
public void setClobInStatement(Connection conn, PreparedStatement ps, String longText) {

// I don't know what 'false' means versus 'true' in the following statement
CLOB c = CLOB.createTemporary(conn, false, CLOB.DURATION_SESSION);

// The 1 is the position to start inserting the string into the clob.
c.setString(1, longText);

// Set the temporary clob in the statement, it becomes permanent when the statement executes.
// If the clob is the first object to be set in the statement, use 1
ps.setClob(1, c);
}

Gotcha’s

  • The PreparedStatement.setString() will work with text up to 4000 characters. With strings longer than that it will fail with a cryptic exception, ORA-00600, I believe.
  • If you’re supporting multiple databases, you’ll have to create an Oracle specific class and implement an interface so you can swap out the implementation. This requires direct use of the Oracle API.

References
La Javadoc En Francais (It’s in english and the most complete)
oracle.sql.CLOB
oracle.jdbc.driver.OraclePreparedStatement

Posted in Programming | Tagged: | Leave a Comment »