Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Too few parameters. Expected 2

Thread view: 
geletine - 21 May 2006 20:13 GMT
>From the earlier example i now have a new ms access data base with
Record_number as autonumber, Artist as Text, Album as Text, Price as
Currency, Release_date as Text and Style as Text
I wrote a program to search for a artist using the Record_number, but
within runtime i get the subject error "Too few parameters, Expected 2"
I presume currency is equal to Double in java.

Here is the code

import java.sql.*;
import java.io.*;
public class Car2 {
public static void main(String args[]){
Connection connection;
  Statement st;
  String out="";
String display="";
 String  RecordNumber ="";  // received from user
BufferedReader stgin = new BufferedReader ( new InputStreamReader (
System.in ) );

  try{
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  connection= DriverManager.getConnection("jdbc:odbc:Records","","");
  st = connection.createStatement();
System.out.println("Enter record number");
RecordNumber = stgin.readLine();

         PreparedStatement ps =
connection.prepareStatement(
 "SELECT Arist, Album, Price, Release_Date, Style " +
 "FROM albums where RecordNumber = ? ");

ps.setString(1, RecordNumber);

ResultSet rnum = ps.executeQuery();
 while (rnum.next()) {
                       out=" : " + rnum.getString("Artist")+"\t"+
rnum.getString("Album")+"\t"+ rnum.getDouble("Price") +
"\t"+ rnum.getString("Release_Date")+"\t"+ rnum.getString("Style");  ;

display = out;
System.out.println (display);
   }
   }catch (Exception e) {
  e.printStackTrace();
 }
 }
 }

at runtime

Enter record number
3
java.sql.SQLException:[Microsoft][ODBC Microsoft Access Driver] Too few
parameters. Expected 2.
at sun.jdbc.odbc.jdbcodbc.createSQLException<JdbcOdbc.java:6958>
at sun.jdbc.odbc.jdbcodbc.standardError<JdbcOdbc.java:7115>
at sun.jdbc.odbc.jdbcodbc.SQLExecute<JdbcOdbc.java:3150>
at
sun.jdbc.odbc.jdbcodbcPreparedStatement.execute<JdbcOdbcPreparedStatement.java:214>
at
sun.jdbc.odbc.jdbcodbcPreparedStatementQuery.execute<JdbcOdbcPreparedStatement.java:89>
at Car2.main.<Car2.java:32>
geletine - 21 May 2006 20:41 GMT
Arist should be Artist
now it works
Rhino - 21 May 2006 23:26 GMT
> Arist should be Artist
> now it works

I saw that error and was going to point it out but it didn't seem that this
could cause the error message you got so I didn't say anything!

--
Rhino
geletine - 22 May 2006 18:46 GMT
> > Arist should be Artist
> > now it works
[quoted text clipped - 4 lines]
> --
> Rhino

Next time i should compile with -verbose, i am not sure if that would
help but it would tell me   information about each class loaded and
each source file compiled.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.