SqlException: At least one parameter to the current statement is uninitialized

When you do the Using Databound Components to Access a Database tutorial, you learn how to use the Query Editor on the rowset to build the SQL statement to retrieve the desired set of data. You also learn that for every ? (parameter) in your query, you need to call setObject() on the rowset before the query is executed. Take, for example, the following query.

SELECT ALL TRAVEL.TRIP.TRIPID, 
           TRAVEL.TRIP.PERSONID, 
           TRAVEL.TRIP.DEPDATE 
FROM TRAVEL.TRIP
WHERE TRAVEL.TRIP.PERSONID = ?
   AND TRAVEL.TRIP.TRIPTYPEID = ? 
This query has two parameters, PERSONID and TRIPTYPEID. What this means is that you have to provide values for these two parameters before the rendering phase. You typically do this in the prerender() method, as shown in the following code example.
public void prerender() {
    if ( personIdDD.getSelected() == null ) {
        try {
          personDataProvider.cursorFirst();
          getSessionBean1().getTripRowSet().setObject(
            1, personDataProvider.getValue("PERSON.PERSONID"));
          getSessionBean1().getTripRowSet().setObject(
            2, "4");
          tripDataProvider.refresh();
        } catch (Exception e) {
          error("Cannot switch to person " +
              personDataProvider.getValue("PERSON.PERSONID"));
            log("Cannot switch to person " +
              personDataProvider.getValue("PERSON.PERSONID"), e);
        }
    }
}

If you forget to set the parameters before the rendering phase, you usually get the following error.

SqlException: At least one parameter to the current statement is uninitialized.

You will also get an error like this if you do not set all the parameters. Such as only calling setObject(1, somevalue) when you have two parameters in the query.

Another common error is to forget to edit the query to add the parameters. If you call setObject(1, somevalue), but your query has no parameters (no ?), you might get an error like the following.

java.lang.NullPointerException
at org.apache.derby.client.am.PreparedStatement.checkForValidParameterIndex(Unknown Source)

Similarly, if you call setObject(2, somevalue) when your query has only one parameter, the server will emit something like the following message.

SqlException: The parameter position '2' is out of range.  
The number of parameters for this prepared  statement is '1'
Comments:

Dear Divas :)

I got the problem with data access too .. and I dont know the solutions yet. I use NB 5.5.1 (with the latest VWP).

My code is like this:
public String button2_action() {
String sjno = (String)getHiddenSPANo().getValue();
String dono = (String)getHiddenDoNo().getValue();
dono = dono.trim();
sjno = sjno.trim();

if(sjno == null || sjno.equals("null")){
sjno = "";
}
sjno = sjno.concat("%") ;

if (dono == null || dono.equals("null")){
dono = "";
}
dono = dono.concat("%");

java.sql.Date sjtgl = new java.sql.Date(getTxtSTglSj().getSelectedDate().getTime());

try{
getSessionBean1().getVrpic0spahdRowSet().setObject(1,sjno);
getSessionBean1().getVrpic0spahdRowSet().setObject(2,dono);
getSessionBean1().getVrpic0spahdRowSet().setObject(3,sjtgl);
getSessionBean1().getVrpic0spahdRowSet().execute();
vrpic0spahdrDataProvider.refresh();
vrpic0spahdrDataProvider.cursorFirst();
tabSet1.setSelected("tab2");
}catch(Exception e)
{
error(e.getMessage());
log("ERROR:",e);
}

return null ;
}

I use table to bind the data .. and each column i gave the button to view the detail.

When I tried to open some details,
and then going back to open the first record (i am sure the query is correct, because i use printstament on the dataprovider).... it sometimes display blank .. and when I refresh .. it will display the data ... that's weird.

I tried to debug by adding this code on the button:

String temp = (String) vrpic0spahdrDataProvider.getValue("SPAHDNO");
error(temp.concat("!"));

it produce Index out of bound exception: CachedRowSetRowKey[0]

I dont know why it happens ... any solutions ? (it only happen when I tried to browse some details and then click on the first record).

Posted by adwin on September 06, 2007 at 05:18 PM PDT #

additional info:
the data provider return rowcount = 0 (means data not found)... but i am sure the data was there and the weird is it happen sometimes.
:(

Posted by adwin on September 06, 2007 at 05:30 PM PDT #

Adwin, I suggest that you submit this question to the nubusers alias (see http://www.netbeans.org/community/index.html). There are a lot of experience Visual Web developers to help you solve your problem. By using the alias you also give the readers the opportunity to ask further questions to help identify your logic error. For example, when you say "and then going back to open the first record" they will ask for some less ambiguous description. How did you "go back"? Did you click on a button component on the detail page that navigated back to the first page, or did you click the back button on the browser? When you say "going back to the first record" what exactly do you mean. How are you going back to the first record.

Posted by Diva #2 on September 07, 2007 at 07:33 AM PDT #

I came across this in the TravelCenter sample app. The out of bounds that is.

I'm running the OpenSolaris dev edition with NB6. Although it is Beta I would still explect the sample app to work.

I'm not sure this is entirely down to being a nub...

Posted by Andy on December 01, 2007 at 12:53 AM PST #

Andy,

The final version of NetBeans 6 is coming out soon. If you see this problem, please file a bug at http://www.netbeans.org/kb/articles/issuezilla.html

Posted by Diva #2 on December 01, 2007 at 02:37 AM PST #

Tengo un problema con la propiedad ColumnClass del gridPanel, le asocio las clases para tres columnas pero en tiempo de ejcucion no me las toma, y segun lo que dice la ayuda de netbeans 5.5.1 debe ir separadas por comas pero el mismo ide no me deja ponerle comas tengo que agregarselas por codigo jsp, osea modificando el codigo que netbeans genera, que estoy haciendo mal o es un bugs de la IDE

Posted by Jaider Rdoriguez on March 18, 2008 at 11:55 AM PDT #

Jaider, I am not sure I understand your question. Does http://blogs.sun.com/divas/entry/centering_web_ui_components_on help?

Posted by diva #2 on March 19, 2008 at 01:46 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

divas

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today