Why am I getting the error SQLException: [Microsoft][ODBC Excel Driver] Too few parameters. Expected 1
I am using the following code for uploading keywords & count to an Excel file. I am having keyword_id
as a primary key for that one. I am having the two columns in the Excel file. 1.keyword and 2.count
My code is:
while (rs.next()) {
System.out.println("inside ");
String keyword = rs.getString(1);
int count = rs.getInt(2);
System.out.println("insert into SEARCHABLE_KEYWORDS values ('"+
keyword+"','"+count+"')");
st开发者_开发知识库mtdb.execute("insert into SEARCHABLE_KEYWORDS (keyword_id,keyword,count) values ('"+
"select Searchable_Keywords_sequence.nextval from dual"+
"','"+keyword+"','"+count+"')");
System.out.println(keyword + " " + keyword+" count "+count);
}
but I am getting the following error:
java.sql.SQLException: [Microsoft][ODBC Excel Driver] Too few parameters. Expected 1.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6998)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7155)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3151)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:378)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:284)
at keywordsreader.main(keywordsreader.java:42)
count
is a reserved keyword so if you have a column in your SEARCHABLE_KEYWORDS
table called count
then you need to put the column name in double quotes (")
Doublecheck the column names in your query. Does the table SEARCHABLE_KEYWORDS
has the columns KEYWORD_ID
, KEYWORD
and COUNT
? As far as I know this error message often is cause by typos or wrong spelling of your column names.
As mentioned by mikej you should also make sure not to use reserved keywords inside your statements without putting them in quotes. This tip applies to your column with the name COUNT
.
You are defining in your SQL an insert for two values, but you are selecting three.
insert into SEARCHABLE_KEYWORDS (
keyword_id,keyword,count
) values ('"+
"select Searchable_Keywords_sequence.nextval from dual"+
"','"+keyword+
"','"+count+"')")
`
精彩评论