【问题标题】:Exception in thread "main" java.sql.SQLException: No value specified for parameter 1线程“main”java.sql.SQLException 中的异常:未为参数 1 指定值
【发布时间】:2016-09-24 19:55:38
【问题描述】:

当我执行程序时,它显示错误:No value specified for parameter 1

此语句出现错误:'rowSet.execute();'

public static void main(String[] args) throws SQLException {
    // Create a RowSet Instance
    RowSet rowSet = new com.sun.rowset.JdbcRowSetImpl();

    // Establish the Databse Connection
    rowSet.setUrl("jdbc:mysql://localhost:3306/jmysql?autoReconnect=false&useSSL=false");
    rowSet.setUsername("root");
    rowSet.setPassword("root!@#$Mysql2016");
    rowSet.setCommand("SELECT userpassword FROM user WHERE userid = ? "
            + " AND userName = ? ");
    //Execute the Sql Command
    rowSet.execute(); 

    rowSet.setInt("userid", 415);
    rowSet.setString("UserName", "anjeetSharma415@gmail.com");

     // Display the UserPassword
    System.out.print("Password : " + rowSet.getString(3));

    // Close the Connetion
    rowSet.close();
}

线程“main”java.sql.SQLException 中的异常:未指定值 对于参数 1 在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) 在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:988) 在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:974) 在 com.mysql.jdbc.SQLError.createSQLException(SQLError.java:919) 在 com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2611) 在 com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2586) 在 com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2510) 在 com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2259) 在 com.sun.rowset.JdbcRowSetImpl.execute(JdbcRowSetImpl.java:567) 在 com.advjdbc.database.chapter.RowSetPerParepedStatement.main(RowSetPerParepedStatement.java:30)

【问题讨论】:

    标签: java mysql jdbc


    【解决方案1】:

    您收到异常的原因是您在设置所有参数之前调用了execute() 方法。 所以你必须设置参数如下(在execute()方法之前):

    rowSet.setUrl("jdbc:mysql://localhost:3306/jmysql?autoReconnect=false& useSSL=false");
    rowSet.setUsername("root");
    rowSet.setPassword("root!@#$Mysql2016");
    rowSet.setCommand("SELECT userpassword FROM user WHERE userid = ? AND userName = ? ");
    
    // set the param values
    rowSet.setInt(1, 415);
    rowSet.setString(2, "anjeetSharma415@gmail.com");
    
    //Execute the Sql Command
    rowSet.execute(); 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多