• Post Reply Bookmark Topic Watch Topic
  • New Topic

Runtime error while executing sql query using JDBC  RSS feed

 
upanshu vaid
Ranch Hand
Posts: 83
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranch,
I am not getting the desired output while running this code
import java.sql.*;
class Jdbctest{
protected Jdbctest(){
}
public static void main(String args[])
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException ce){
System.out.println(ce);
}
try{
String url="jdbcdbc:Employeemain";
Connection con=DriverManager.getConnection(url);
Statement s=con.createStatement();
ResultSet rs=s.executeQuery("SELECT * FROM EMPLOYEE " +"WHERE Minit=' T ' ");
for(int i=0;i<=8;i++)
{
rs.next();
System.out.print(rs.getString(1)+"\t");
System.out.print(rs.getString(2)+"\t");
System.out.print(rs.getString(3)+"\t");
System.out.print(rs.getString(4)+"\t");
System.out.print(rs.getString(5)+"\t");
System.out.print(rs.getString(6)+"\t");
System.out.print(rs.getString(7)+"\t");
System.out.print(rs.getString(8)+"\t");
System.out.print(rs.getString(9)+"\t");
System.out.print(rs.getString(10)+"\t");
System.out.print(rs.getString(11)+"\t");
System.out.println(" ");
}
con.close();
}
catch(SQLException ce){
System.out.println(ce);
}
}
}

Runtime error i am getting
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Too few paramet
ers. Expected 1.

kindly help on this.

Thanks
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

It seems that Statement is for executing queries without parameters, that is 'T'. For queries with parameters use PreparedStatement.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!