File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes why is this code not executing in java environment Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "why is this code not executing in java environment" Watch "why is this code not executing in java environment" New topic

why is this code not executing in java environment

dan steve

Joined: Feb 12, 2011
Posts: 7
I have this code to select some values from the database and its working fine in the database engine but throwing "parameter too few
one expected " what does this mean? this is the sql code.

this code is part of a method where I declared the string parameter(String lic_no) and the method name : public arrayList getTotalFine
(String lic_no) please help me its urgent.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

There is no such thing as urgent; please EaseUp.

How To Ask Questions How To Answer Questions
Matthew Brown

Joined: Apr 06, 2010
Posts: 4544

How are you running that SQL from Java?
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 199
Hi dan,Welcome to ranch community....
Always remember...PatienceIsAVirtue...
There can be two reasons for the exception thrown by your code-

1.You are using any reserved keyword in your SQL query(As far I concerned,there is nothing like this),If there is any use double quotes arround that(" ").
2.You are using mis-spelled column names or less than expected column names in your query.

Check against both the possibilities.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15093

I don't know how you are running that SQL statement exactly from your Java code, but note the following. It is a bad idea to concatenate an SQL statement together with values, like you're doing:

What happens if lic_no contains a characters that make your SQL statement invalid (for example, a single quote character)? This code is also vulnerable to a simple and common security problem, SQL injection. To prevent these problems, always use a PreparedStatement, like this:

The PreparedStatement will take care of proper escaping if lic_no contains text that make the SQL statement invalid, which also prevents the SQL injection vulnerability.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: why is this code not executing in java environment
jQuery in Action, 3rd edition