Marketplace for Content, Tests and Assessment
 
 

Archive

Author Archive

Output parameter not allowed as argument list prevents use of RPC.

April 20th, 2010 sadhna No comments

While calling a stored procedure from my java class; I was getting the following  error-

java.sql.SQLException: “Output parameter not allowed as argument list prevents use of RPC.”

After doing a little research; I found that When calling a stored procedure that has output parameters, the driver has to call the procedure using a remote procedure call (RPC). Stored procedures should be invoked using the special JDBC call escape syntax.

For example, {call stored_Proc1(?,?,?,?)}.

In this case the driver will be able to use an RPC successfully as all the parameters are represented by parameter markers (?). If however parameters are supplied as a mixture of parameter markers and literals,

for example {call stored_Proc1(?,’ ‘,?,0)}

Then the driver is unable to use an RPC and therefore cannot return output parameters. In these circumstances the driver raises the above exception and execution fails.

It is possible to use mixed parameter lists to call stored procedures that do not have output parameters. In this case the driver will substitute the parameters locally and use a normal “execute procedure” SQL call; however, this mode of execution is less efficient than an RPC.

Categories: Programming / tutorials Tags: , ,

Jboss 4 Server Configuration changes for SQL Server 2008

April 5th, 2010 sadhna No comments

Last week our Sql Server was upgraded to 2008 version. And the upgrade , I found following exception being thrown by when deploying our project.

com.microsoft.sqlserver.jdbc.SQLServerException: The server version is not supported. The target server must be SQL Server 2000 or later.

I upgraded the jdbc driver and replaced to sqljdbc.jar (version 2.0) and stored in lib folder of my project.
But the error was same as under— Read more…

JNDI lookup on JBoss

March 11th, 2010 sadhna No comments

There is no standard way as per Java EE specs for  JNDI naming conventions, hence most of the application servers have their own way of JNDI naming.

On specifying a Datasource’s JNDI name as ‘myDatasource’, JBoss binds as ‘java:myDatasource’. So if one want to deploy the application on Jboss application servers then can use the simplest way is here. The steps for adding and using jndi Datasource to JBOSS 4.x is as under-

  • Copy the jdbc driver to JBOSS_HOME/server/default/lib.
  • Create the jndi xml file for datasource – example ds.xml Read more…

Categories: Programming / tutorials Tags: , ,

Groovy Tutorial – Calling a stored procedure

December 2nd, 2009 sadhna No comments

Calling a stored procedure from a Sql server MySQL database or any other database in groovy is simple. First we need a datasource which spring could provide for us. Do the necessary datasource mapping in the resources.xml ( spring folder) in your grails folder &/Or datasources.groovy.

In service, use the datasource to call a store procedure as below example

import groovy.sql.Sql
class TestService{
def dataSource // using the datasource we define in the spring's resources.xml

/**Calling Procedure with in-parameters only- use sql.query**/
def abcList = { params ->
Sql sql = new Sql(dataSource)
def clientkey = (SecurityUtils.getSecureClientKey(params) !=
null)?SecurityUtils.getSecureClientKey(params):1
//calling proc that returns resultset
sql.query("{call svr_RetrieveClientPreferences(?)}",[clientkey]) { rs ->
if (rs != null) {
int i = 0
while (rs.next()) {
/ *all functionality ...... */
}
}
}
}

/**Calling Procedure with in & Out parameters - use sql.call **/
def abcCalc = { params ->
Sql sql = new Sql(dataSource)
guid = params.guide
userKey = params.user
//calling proc that returns out parameters
sql.call("{call gdx_ReadSessionData(?,?,?,?,?,?)}",
[guid, userKey, Sql.out(Sql.INTEGER.type),
Sql.INTEGER, Sql.VARCHAR, Sql.INTEGER])
{ date,userKeyCode,msgCode,retCode -> /* The out parameters will be returned in the same order it passed to procedure */
userKey = userKeyCode
println(" return code" + retCode)
}
}
}

Note-
in-Out Param can be passed as Sql.out(Sql.<DATATYPE>.type) OR Sql.<DATATYPE> .
See more for DATATYPE here – http://groovy.codehaus.org/api/groovy/sql/Sql.html
LIMITATION -
Some issues with groovy sql; where we want to use out parameters & resultset both as a return of proc execution.

In this case we have to use the jdbc way (callable stmt) where stored procedure that return ResultSet and OUT parameter.

Categories: Programming / tutorials Tags:

Groovy Closures

August 31st, 2009 sadhna No comments

Groovy supports closures and they are very useful when we create Groovy applications.

The most important difference between a normal function/method and a Closure is that Closures can be passed onto other functions as arguments and they serve as Callbacks to the calling function.

For example we can pass closures as arguments to methods to execute them. We can create closures ourselves, but we can also convert a method to a closure with the .& operator. And we can use the converted method just like a normal closure. Because Groovy can use Java objects we can also convert a Java method into a closure.

syntax to write Closure-

def closure1 = {params ->
//statements & logic
}
e.g-
//type 1  - closure without any parameter
def closure2 = {
    println "Test Only"
}
//type 2 – closure with two param
def closure3 = { String name, int age ->
    println "My name is : $name and age is: $age"
}

A Closure is usually defined within the braces {… }. Parameters defines the list of parameters that are to be passed for the closure. The symbol '->' is used to separate the Arguments with the set of statements in the Closure Definition.
call a Closure Definition-

closure1.call( args )
closure1(args )
e.g 

closure2()
closure2.call()
output- 
Test Only
Test Only
-------------------------------------------
closure3("sadhna", 30)
closure3.call("saisha", 3)

output- 
My name is : sadhna and age is: 30
My name is : saisha and age is: 3

Like ‘this’ keyword which refers to the current object, there is ‘it’ keyword which, when used within a Closure Definition refers to the default first parameter being passed to the method. The following code will prove that,

def closure4 = {
    println it
}
Closure4.call("Test Again")
Closure4.call()

Output--
Test Again
null

Java  method  to  groovy closure

public class Test {
 public static void javaTest(final String s) {
  System.out.println("Java --" + s + "!");
 }
}

With the following script we use this Java class and convert the javaTest method to a closure:
// Simple list with names.
def names = ['groovy', 'grails', 'closure']
// Simple closure.
names.each { println 'Closure --' + it + '!' }
// Groovy method to convert to closure.
def groovySays(s) {
 "Groovy --${s}!"
}
// Use .& syntax to convert method to closure.
names.each(this.&groovySays)
// Convert Java method to closure and use it.
def javaTest = Test.&javaTest
names.each javaTest

output-
Closure --groovy!
Closure --grails!
Closure --closure!
Groovy --groovy!
Groovy --grails!
Groovy --closure!
Java --groovy!
Java --grails!
Java --closure!

Grails tutorial – How to create and run First Application in Grails

July 23rd, 2009 sadhna No comments

I am hoping you would have gone through Introducing Grails and then the Part 1 of this post Setting Up Grails .

Now I am covering the details of developing and running the application

1. Go to command prompt and your grails home directory.
2. Create the application.

  • The create-app command creates the full project, with a template with placeholders for the different components of your application such as configuration, MVC, library, and much more.
  • > grails create-app   (it will ask for a application name say – first_app)
  • Will create basic  view layout as main.gsp page Read more…

Setting up Grails

July 8th, 2009 sadhna No comments

In case you have  missed it , here is the first post Introduction to Grails

Before creating the first grails application we need to first  install & set up grails environment –

  1. Go to http://www.grails.org/Download , Download and unzip grails.
  2. Create a GRAILS_HOME environment variable.
  3. Add $GRAILS_HOME/bin to the PATH.

Pre-requisite -  Jdk 1.4 or above.

Cool thing about Grails is you don’t need to install server or database for running test apps. web server is ‘jetty’ server comes with grails so you do not need to install separately. But if you want to use any other server like tomcat , jboss   ..,you can.

Grails also comes with HSQLDB, a pure-Java database. Using another database, such as mysql or Oracle Database is just changing the dbdriver in DataSource.groovy ,thanks to Hibernate and GORM.

Enjoy setting your machine for start Grailing.

Update:  In this post, how to create and run First Applications . I am covering the next steps for starting development

Grails – A breath of fresh air for Java people

June 26th, 2009 sadhna 1 comment

I’ve been working in J2ee/java technologies from 8 years and really loved it. Never wanted to switch or look anything beyond java but started working on Groovy & Grails recently, few months ago, and found that in terms of developer productivity it seems to be light years ahead of other Java solutions (spring, Struts, EJB, JSF, JSP).

What is Groovy-

Groovy is a dynamic language which runs on the Java platform. It has Java-like syntax, although it’s not fully compatible with Java. (i.e. many Java programs are valid Groovy code, but not all.)Consider Groovy if you’re looking for a scripting language with dynamic language features and must deploy your applications on a JVM.

What is Grails-

Grails is an open source web framework for the Java platform. However, unlike other MVC model framework-

  • Grails domain classes are automatically persistable and can even generate the underlying database schema.
  • Services and other classes can be automatically injected using dependency injection based on naming conventions.
  • Grails controllers are request-scoped, which means a new instance is created for each request.
  • The default view for Grails is Groovy Server Pages (GSP) and typically renders HTML. The view layer also includes a flexible layout, a templating feature, and simple tag libraries.

I found Grails and java as -

  • Groovy is not evolution of Java but groovy compliments java.
  • Grails offers some of the best features with seamless Java, Spring & Hibernate integration allowing you to scale in terms of complexity as your application grows.
  • Groovy and Grails feel very natural to a Java programmer
  • Grails definitely has its own unique features such as dynamic tag libraries, a view technology that is not scriptlet based, the ability to use dynamic finders and persistence methods on any Groovy or Java class and its tight integration with Java, Spring & Hibernate.
  • You can develop a Grails application without knowing anything about Spring, Hibernate or SiteMesh
  • A Java development like Struts & EJB is a very configuration heavy approach, with Grails you can build an entire application and only ever have to configure the data source.
  • Groovy & Grails are very easy on the surface and allow you to be expressive and creative as a developer. They don’t, however, take away the underlying power of the JVM and frameworks like Spring & Hibernate.

Grails and in particular Groovy are very close to Java. A few quick lessons in Groovy and a Java developer and quickly feel at home.

The only real pitfall is that it’s based on Groovy and not on Java are -

  • less powerful IDE support.
  • some errors caught by Java at compile-time appear only at runtime in Groovy – this is by design and not a fault of Groovy.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes