File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC 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
Bookmark "why is this code not executing in java environment" Watch "why is this code not executing in java environment" New topic
Author

why is this code not executing in java environment

dan steve
Greenhorn

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
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

There is no such thing as urgent; please EaseUp.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4387
    
    8

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

Joined: Oct 17, 2009
Posts: 198
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: 14146
    
  18

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 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why is this code not executing in java environment