Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, December 11, 2012

Fix: Add Apache Derby Nature in Eclipse does nothing

Tonight I had a strange issue with Eclipse: adding the Apache Derby nature to an Eclipse project wasn't working. Ordinarily, (provided that the Apache Derby Eclipse plugin is already installed) right-clicking a project and choosing Apache Derby->Add Apache Derby Nature to a project will do just that, enabling additional features such as starting or stopping the Derby network server.

This time, however, choosing that option appeared to do nothing. Rather than a menu full of commands, I was given only the option "Add Apache Derby Nature" in the Apache Derby context menu, which is what I had previously selected. I tried several times to add the nature in this manner, but to no avail.

The fix turned out to be simple. After grepping the directory of another project where I had successfully used Derby, I found that the change should have been reflected in my project's .project file.

The fix: if the Apache Derby nature isn't correctly added to a project through the Apache Derby menu, it can be done manually by editing the .project file (which is in the root directory the project). This is an XML file.

Find the <natures> node and add this line:

<nature>org.apache.derby.ui.derbyEngine</nature>

Here's how the entire <natures> node looks after the change in my project:



<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.apache.derby.ui.derbyEngine</nature>
</natures>

Then, just save the file. Problem solved.

Wednesday, October 21, 2009

Getting Started with Eclipse

For about the last month I have been learning Java. Due to outside requirements, I have been using the BlueJ IDE for development. However today I decided to give Eclipse a try.

I installed version 3.2.2 from the Ubuntu repos and loaded a project I had just completed in BlueJ. It was then that I was greeted with a few errors regarding my code. The first of which was:

    Scanner cannot be resolved to a type

The line of code in question was:

    private Scanner userInput = new Scanner(System.in);

Strange, I thought, since I had made no changes to the code and had just compiled and run this project in BlueJ.

I first checked the installed version of Java:

    $ java -version
    java version "1.6.0_0"
    OpenJDK Runtime Environment (IcedTea6 1.4.1) (6b14-1.4.1-0ubuntu11)
    OpenJDK Client VM (build 14.0-b08, mixed mode, sharing)


    $ javac -version
    javac 1.6.0_0

Ok, everything looked good there. I checked the compiler settings in Eclipse and changed the compiler from 5.0 compliant to 6.0 compliant. No joy.

After some more digging I concluded that the issue was probably that Eclipse was not using the proper JRE. Sure enough, Eclipse was using version 1.5 at /usr/lib/jvm/java-1.5.0-gcj-4.3-1.5.0.0. I added another JRE entry pointing to /usr/lib/jvm/java-6-openjdk (which is what my BlueJ installation was already using) and voila! No more errors.

I guess I should look into cleaning up the multiple JRE's I have installed on this machine.

But first, back to exploring Eclipse!

Monday, October 12, 2009

User Database Manager

As I wrote about back in June, I have been getting back into programming this year. I started off in Python and it went well. Approximately two months in, I was able to write a simple database manager. It actually started as a response to LaRoza's Beginner's Programming Challenge #7 and turned into a bit of a monster as I added more and more functionality once I satisfied the initial requirements. The program is written in Python and uses a sqlite database. The requirements are pysqlite 2.x on the client machine in addition to an installation of Python.

I figured that since the program is robust and feature-complete (albeit limited in scope), it would be worthwhile to officially release it under a GNU GPL. This will happen once I figure out what hosting service and/or version control system to use.  Hopefully, someone out there in learner-land may find it useful.


Sunday, June 14, 2009

Diving into SQLite Using Python

...Or, The Trouble With Tuples.
(Sorry, the pun had to be made).

For the past 3-ish months, I've been teaching myself Python. I started off with Wesley Chun's Live Lessons video tutorials, and later moved on to his book Core Python, 2nd ed. It has been a satisfying ride so far. Not without tribulations of course, but things are coming along nicely.

Once I had learned enough of the basics, I jumped into writing some programs. Simple things at first of course such as number guessing games and the like-- at first taken from textbook exercises, but later also incorporating various other amateur programming challenges I found on the web.

My most recent project is a database manager application. Originally it was a response to a programming challenge posted on the Ubuntu Forums, but slowly developed into a larger and more powerful app as I decided to add more and more features not called for in the assignment.

Development of the app moved along at a steady pace until I implemented record deletion. I could successfully search the DB using a parameter entered by the user and edit the record, but when I tried to delete it I was met with the error:

ValueError: parameters are of unsupported type

This was something I had not previously encountered. After exhausting my available resources, I decided to ask for help on the Ubu-forums. I started a thread (full details about the program and the solution can be found therein) and got my answer in short notice. Essentially it was this:

I had already successfully implemented DB record editing with the statement

cursor.execute('UPDATE main SET FName=?, LName=?, age=? WHERE id=?', (dataFName, dataLName, dataAge, record))

This part of things worked without a hitch. But when, in the same function, I ran

cursor.execute('DELETE FROM main WHERE id=?', (record))

I would get the "unsupported type" error.

The problem, I learned, was with the variable "(record)" that I was passing to the SQLite statement. The data passed needs to be of type Tuple and I was not providing one. I was providing a mutable string!

I was puzzled by the fact that the edit statement worked and the delete statement did not. It dawned on me that I was inadvertently creating a Tuple in the edit statement-- this was completely a by-product of me passing multiple variables across. It just happened to be creating the tuple I needed without me realizing it. With that in mind, what I had to do was make a very small change to the delete statement in order to create a tuple. I added a comma after record so that the statement read:

cursor.execute('DELETE FROM main WHERE id=?', (record,))

And that was all it took! Lesson learned. Things are moving along nicely with this hurdle out of the way and I hope to soon be finished with the app.