Scala, Java, Unix, MacOS tutorials (page 404)

Spring JDBC DELETE FAQ: Can you provide some examples of using SQL DELETE queries using Spring JDBC (Spring Dao classes and methods)?

Here are a few Spring Dao examples, specifically JDBC/SQL DELETE examples.

Spring JDBC delete example #1: Delete a record by the primary key

In this first Spring JDBC DELETE example, I pass in an id parameter, which represents the primary key in my hosts database table. This JDBC/SQL statement deletes the record from that table that matches that id field.

I wrote the following Java class today that is a "helper" class for a project I'm working on to create a web interface for Nagios. The Nagios part isn't too relevant, because mostly what I'm trying to show here is how to use the Apache Commons IO project to make it easier to interact with files and directories from Java code.

In short, the following Java class shows how to use the Commons IO project to accomplish the following tasks. Without any further delay, here is the complete source code for my class:

A Spring JDBC SELECT and INSERT example: Here's the source code for a complete Spring DAO class from a project that I'm currently working on (a Java-based web interface to the open source Nagios project) that shows how to use a few Spring JDBC methods, including both a SELECT example and a simple INSERT example.

I'll add more examples to this site later (and with more introduction/description), but for now I'm just going to drop this Java class sample out here and hope that it helps you "Learn Spring JDBC by example".

A JDBC MySQL transactions tip: If your transactions aren't working with your new MySQL database you may have the same problem I just had. I created my database tables with the default MySQL storage engine (MyISAM), and guess what? MyISAM doesn't support transactions.

I got a really brutal looking error message from Spring and MySQL yesterday. I've been working on a Java-based web interface for Nagios for a client, and I ran into an error message that basically says "Cannot add or update a child row: a foreign key constraint fails". If you like ugly, gruesome error messages here is the full-blown error:

Summary: An Ant multiline text replacement example.

I'm working on a Java project where we recently started using the JNDI capabilities in Glassfish, but our development environment has been to use Tomcat as our application server (without JNDI lookups). To keep my Apache Ant build process working in both environments I quickly learned that I was going to need to perform multiline text replacements with Ant.

I don't know how TextMate decides where it's going to put the project drawer (the drawer that slides out when you open a directory or project instead of opening a file), but sometimes the drawer comes out on the left when I want it on the right, and other times it comes out on the right when I want it on the left.

Unfortunately it's not at all obvious how you're supposed to move the project drawer from one side to the other, but after digging through the help documentation I finally found it.

Slow Apple TimeCapsule backups: Two tips for increasing the speed of Apple TimeCapsule backups.

I've found the initial backup with the Mac Time Machine software and the Apple Time Capsule to be very slow, you might say "insanely slow". ;) I'm trying to perform the initial backup using a MacBook Pro over a Wireless-G network in my home network to a 500 GB Time Capsule that I just purchased, and it has been crawling along.

Spring JDBC Example/Question: How do I perform a SQL DELETE query (statement) using JDBC and the Spring Framework?

Here's a simple Java method that I created to perform a SQL DELETE using Spring JDBC techniques:

Here's a quick look at how to get the generated key from a MySQL database table after performing a SQL INSERT statement on a table that has an auto_increment field. (Some databases also refer to this as an identity field.)

To get the generated key from a MySQL database table, just use the MySQL LAST_INSERT_ID function, calling it as shown below, immediately after performing your INSERT command (and very importantly, also using the same connection):

While traveling the other day I was looking for some free wireless internet access, and when I looked in the Wireless/AirPort menu on my MacBook Pro I noticed the usual listing of publicly broadcasting wi-fi networks in the top part of the menu, but then under the "Devices" portion of the menu I noticed an entry labeled "Free Public WiFi". For a brief moment that sounded like what I needed, but then the alarms in my head went off, as it sounded more like a trap, something like the typical worm/virus/hacker/phishing setup.

When you need to forward from one JavaServer Page (JSP) to another JSP, here's all you have to do:

<jsp:forward page="/faces/success.jsp" />

In the example shown I happen to be working on a small JavaServer Faces (JSF) application, so the URL in this example includes the string /faces/.

 

Today I was working with a class that extended the Spring class NamedParameterJdbcDaoSupport, and when I went to use the getNamedParameterJdbcTemplate().queryForObject() method, the third parameter of the method required a Class reference.

Here's some free source code for a Perl program I've created to read and analyze standard Apache access log files and print out the most popular pages. As shown below it will print out the top 100 popular pages on your website, but that is easily changed.

The code could use a lot of improvement, and I will continue to post updates here when I make improvements. Other than that it's provided here free of charge, so feel free to make your own improvements to it as well.

You'll probably have to know a little bit about Java, Ant, and build files for this sample build.xml file to be any use to you, but if you're looking for a sample Ant build script that can be used to create a war file, or one that simple uses a war task, this example might work for you.

I'm not going to provide any explanation of any of this right now, but if I have time in the future I'll come back here and add a few comments about how this build script works.

Some time ago I created a brief blog entry that shows an HTML select/option block for displaying all the states in the United States in a dropdown list (combo box). After a few requests I'm now providing that same information here in a database table format.

When I create a web-based user interface I tend to be a fanatic about making sure that the first input field on a form gets input focus when the form is first displayed. It always drives me crazy when I go to a web form that requires text input, but the developer of the page hasn't taken the time to put the default focus in the first field of the form.

So ... after looking around at some HTML/JSF/Struts/JSP code I've written over the last few years, the following JSF example shows the most concise way I know of setting default input focus on an HTML form field:

vi/vim search and replace FAQ: How do I search and replace in vim?

A lot of people ask me how to perform a global search and replace operation in the vi (vim) editor. The vim editor is anything but intuitive, but for some reason I can remember this global search and replace syntax pretty easily.

vim FAQ: How do I perform a vim “search and delete” using a vim regular expression pattern (regex)?

Every once in a while when I’m using the vi editor (or vim) I find myself in a situation where I need to delete a bunch of lines in the file that match a particular pattern. In my younger days I used to get out of vi and then use sed or grep to get rid of those lines, but it turns out there’s a real easy way to do this in vi.

In previous blog posts I showed how I created a Java web service and client using Apache Axis2. In those examples I showed how to read from web service methods that return a single object, and also an array or list of objects. In this post I'll show several sample Ruby programs that also read from those same Java web services.