Skip to content
accelerando

Tag Archives: Tipps

JDBC: Autogenerated keys revisited.

02-Apr-08

Some months ago i wrote about retrieving auto generated values with JDBC from an Oracle Database: JDBC: Get autogenerated keys on a Oracle DB.

The solution i presented in the previous article doesn’t run in a Oracle Java Stored Procedure.

To accomplish this, use a callable statement like this:

final String sql = "BEGIN INSERT INTO foobar(id, b) VALUES (id.nextval, ?) RETURNING id INTO ?; END;";
CallableStatement cs = connection.prepareCall(sql);
stmt.setString(1, "bar");
stmt.registerOutParameter(2, Types.INTEGER);
stmt.executeUpdate();		
rv = rs.getInt(2);

This way you get the id generated by the sequence id without first selecting and then using it.

Safari Webinspektor

08-Jan-08

Vor fast 1.5 Jahren schrieb ich im Zusammenhang mit Daily Fratze on rails über den Safari Inspektor, der damals nur in den Nightlies verfügbar war: Damaliges Daily Fratze Preview.

Leider habe ich den Inspektor im aktuellen Safari 3 nie mehr gesehen, bis ich vor ein paar Tagen auf das SülzOMat Blog stieß. Einfach im Terminal folgenden Befehl absetzen:

defaults write com.apple.Safari WebKitDeveloperExtras -bool true

Safari neu starten und man hat über das Kontextmenü den neuen Punkt “Element-Informationen”, der den Inspektor startet, der dem beliebten Plugin “Firebug” für Firefox in kaum etwas mehr nachsteht.

Vielen Dank für diesen Beitrag!

Copy and paste within cmd (command interpreter under Windows)

13-Dec-07

Under Windows 2k and XP exists no keyboard shortcut in cmd.exe to copy and past text. You need not only use your mouse but hit the proximity icon in the top left and choose edit|mark, edit|copy and so on.

cmd has a special mode named QuickEdit which can be enabled via the following command

REG.EXE add HKCU\Console /v QuickEdit /t REG_DWORD /d 1 /

all new cmd windows will now be in QuickEdit mode. Text can be selected with the left mouse button, copied via right mouse button and pasted via right mouse button.

Found on a msdn blog. Thanks!

Disable Ruby On Rails Sessions

20-Nov-07

Just a reminder to myself, but maybe it’s usefull for others as well.

Some days ago i stumpled upon the fact, that one can turn off session support in controllers in rails: HowtoChangeSessionOptions (see Disabling Sessions) or HowtoPerActionSessionOptions.

I found it particularly useful and convenient for my Feed controller, which is dedicated entirely to feed generation (yeah, i know about about REST and especially respond_to, but i wouldn’t get rid of thousands of useless sessions without an explicit controller:

class FeedsController < ApplicationController
  session :disabled => true
end

Java: Creating a Stream on a ByteBuffer

18-Oct-07

This example is plain wrong. The InputStream will cause an endless loop as it always returns a value >= 0. Working code as follows:

private static InputStream _newInputStream(final ByteBuffer buf) {
	return new InputStream() {
		public synchronized int read() throws IOException {				
			return buf.hasRemaining() ? buf.get() : -1;
		}
 
		public synchronized int read(byte[] bytes, int off, int len) throws IOException {			
			int rv = Math.min(len, buf.remaining());				
			buf.get(bytes, off, rv);
			return rv == 0 ? -1 : rv;
		}
	};
}
Close
E-mail It