Wednesday, November 11, 2009

Why Prepared Statements are important and how to use them "properly"

http://www.theserverside.com/tt/articles/article.tss?l=Prepared-Statments
.....
How does a database execute a statement?
Obviously, don't expect alot of detail here; we'll only examine the aspects important to this article. When a database receives a statement, the database engine first parses the statement and looks for syntax errors. Once the statement is parsed, the database needs to figure out the most efficient way to execute the statement. This can be computationally quite expensive. The database checks what indexes, if any, can help, or whether it should do a full read of all rows in a table. Databases use statistics on the data to figure out what is the best way. Once the query plan is created then it can be executed by the database engine.

It takes CPU power to do the access plan generation. Ideally, if we send the same statement to the database twice, then we'd like the database to reuse the access plan for the first statement. This uses less CPU than if it regenerated the plan a second time.
....
When the J2EE server gives your application a connection, it isn't giving you the actual connection; you're getting a wrapper. You can verify this by looking at the name of the class for the connection you are given. It won't be a database JDBC connection, it'll be a class created by your application server. Normally, if you called close on a connection then the jdbc driver closes the connection. We want the connection to be returned to the pool when close is called by a J2EE application. We do this by making a proxy jdbc connection class that looks like a real connection. It has a reference to the actual connection. When we invoke any method on the connection then the proxy forwards the call to the real connection. But, when we call methods such as close instead of calling close on the real connection, it simply returns the connection to the connection pool and then marks the proxy connection as invalid so that if it is used again by the application we'll get an exception.

Wednesday, November 04, 2009

Import/Export keys preferences in Eclipse

Export preferences using : File -> Export -> Preferences ->"Choose Specific Preferences to Export" & choose "Keys Preferences"

You import the preferences file into your new workspace using File->Import -> Preferences.

See "Save your Shortcuts" section - http://robertmarkbramprogrammer.blogspot.com/2007/07/eclipse-shortcuts.html

Tuesday, November 03, 2009

Generate Java Beans from Database

http://wiki.netbeans.org/DevFaqAppClientOnNbPlatformTut

1) Create an Enterprise Application Project (with Application Client and EJB module) in Netbeans
2) Right click on ejb project in Project tab and select New -> Entity Classes From Database. In wizard chose as datasource jdbc/sample datasource and select the tables that need the entity beans.

Using the Spring Framework with the Teradata Plug-in for Eclipse

http://developer.teradata.com/tools/articles/using-the-spring-framework-with-the-teradata-plug-in-for-eclipse

This will be a series of articles explaining how the Spring framework can be used with the Teradata Plug-in for Eclipse to create a data access layer for your business services. The Java Bean Wrapper wizard allows the user to quickly generate a Java Bean class for a given SQL statement or stored procedure. Also the Wizard has an option to generate a Java Bean which
can be run with the Spring Data Access Object (DAO) framework. By calling a generated Java Bean from a DAO, the Bean will have access to the Spring transaction management. Also the Java Wrapper Beans are reusable components which could be used in different DAOs. The Bean Helper Classes can be used as Spring domain objects. Also the Bean will facilitate the support of OUT
parameters for stored procedures and multiple result sets inside of a Spring DAO.
This article will show how to setup a project that uses Spring DAOs with the Teradata Plug-in for Eclipse. This article will also show how to create Java Bean Wrapper classes that can be called from a Spring DAO using the Java Bean Wrapper Wizard.



http://developer.teradata.com/tools/articles/getting-started-with-teradata-plug-in-for-eclipse