Too few parameters. Expected 2

G

geletine

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:eek:dbc: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>
 
R

Rhino

geletine said:
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!
 
G

geletine

Rhino said:
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!


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top