aspose file tools*
The moose likes JDBC and the fly likes Runtime error while executing sql query using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Runtime error while executing sql query using JDBC" Watch "Runtime error while executing sql query using JDBC" New topic
Author

Runtime error while executing sql query using JDBC

upanshu vaid
Ranch Hand

Joined: Sep 07, 2012
Posts: 73

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
Volodymyr Levytskyi
Ranch Hand

Joined: Mar 29, 2012
Posts: 505
    
    1

Hello!

It seems that Statement is for executing queries without parameters, that is 'T'. For queries with parameters use PreparedStatement.

True person is moral, false is right!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime error while executing sql query using JDBC