« SpringOne 2006 | Main | Browsing and Editing/Uploading Database Images in JSF »

conn, ife, sop & try


conn
, ife, sop & try
Oh, weird
language, isn't it.
These are the code templates I use
most often.

A code template is a nice feature of
JDeveloper.
You type a shortcut, eg try, followed by the

CTRL+Enter
key combination and the equivalent template code
is added in the source editor,
at the point where your cursor was.
It
will also bring any associated imports.

For example,
typing conn in the source editor followed by the

CTRL+Enter
key combination will add the following code:

String username = "scott";
String password = "tiger";
String thinConn = "jdbc:oracle:thin:@localhost:1521:ORCL";
DriverManager.registerDriver(new OracleDriver());
Connection conn = DriverManager.getConnection(thinConn,username,password);
conn.setAutoCommit(false);
return conn;
and the following imports:
import java.sql.*;
import oracle.jdbc.OracleDriver;

I think it's worth you have a look at all the avalable shortcuts:
select menu Tools --> Preferences..., expand  Code Editor and click  Code Templates.
You can see there the shortcuts with a small description.
Selecting any shortcut displays the code as shown in the followin picture:

CodeTemplates:


I had never defined my own template before, but I'll certainly do, after having read Frank's post in his blog:
How to automatically add the class name and creation date to a Java file

Frank explains there how you can create your own template, and take advantage of variables (new in JDeveloper 10.1.3).
In his example, a variable $file$ will automatically get assigned the name of the Class and $date$ the current date.

By googling, I see that Steve also explained How to Create a Code Template for JSTL Choose.
Great !

Comments (2)

Didier Laurent:

Sandra from the JHeadstart group shows an example of a code template usage in her post "JDeveloper Code Template for log4j"

Dave:

Nice tips. I've had some major problems with templates with a new blog - http://www.datingsite-review.com/ - thanks for your tips!

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About This Entry

This page contains a single entry from the blog posted on June 17, 2006 6:21 AM.

The previous post in this blog was SpringOne 2006.

The next post in this blog is Browsing and Editing/Uploading Database Images in JSF.

Many more can be found on the main index page or by looking through the archives.

Top Tags

Powered by
Movable Type and Oracle