回 帖 发 新 帖 刷新版面

主题:修改数据库时参数不足?怎么回事啊?

程序如下:
package dbtest;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ModifyDB {

        public static void main(String []args)
        {
                String JDriver="sun.jdbc.odbc.JdbcDriver";
                String conURL="jdbc:odbc:TestDB";
                String []id={"0002","0003"};
                int []score={90,34};
                try{
                        Class.forName(JDriver);
                       
                }
                catch(java.lang.ClassNotFoundException e)
                {
                        System.out.println("ForName:"+e.getMessage());
                       
                       
                }
                try{
                        Connection con=DriverManager.getConnection(conURL);
                        PreparedStatement ps=con.prepareStatement("UPDATE student set score=? where id=?");
                        int i=0;
                        do{
                                ps.setInt(1, score);
                                ps.setString(2, id);
                                ps.executeUpdate();
                                ++i;
                               
                        }while(i<id.length);
                        ps.close();
                        java.sql.Statement s=con.createStatement();
                        ResultSet rs=s.executeQuery("select * from student ");
                        while(rs.next())
                        {
                                System.out.println(rs.getString("id")+"\t"+rs.getString("name") +
                                                "\t"+rs.getInt("score"));
                               
                        }
                        s.close();
                        con.close();
                       
                }catch(SQLException e)
                {
                        System.out.println("SQLException :"+e.getMessage());
                       
                }
               
        }
}
一运行就会出现下面的提示,我用的是eclpise :
ForName:sun.jdbc.odbc.JdbcDriver
SQLException :[Microsoft][ODBC Microsoft Access Driver] 参数不足,期待是 3。

怎么回事啊?
哪位高手指点下啊.

回复列表 (共1个回复)

沙发

ps.setInt(1, score);
 ps.setString(2, id);
->>

  ps.setInt(1, score[i]);
 ps.setString(2, id[i]);

我来回复

您尚未登录,请登录后再回复。点此登录或注册