国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL步驟報ParameternumberNisnotanOUTparameter錯誤

2024-07-24 12:35:15
字體:
來源:轉載
供稿:網友
  今天上線新模塊,昨天測試通過的代碼,居然在線上報錯.
 
  納尼?
  第一反應是程序哪里寫錯了
  大家查了一上午,問題依舊,毫無頭緒.
  后來居然被本貓發現了問題(頗自豪啊)
  這個其實是權限不足導致的.
 
  模擬問題如下:
 
  已經存在一個用戶,對mvbox庫下的表,有Insert,update,select權限.
  grant select,insert,update on mvbox.* to li@'localhost' identified by 'li';
 
  新建兩個過程.
 
  drop procedure if exists proc1;
  drop procedure if exists proc2;
 
  delimiter $$
 
  create procedure proc1 (in para1 int , out para2 int)
  begin
      select para1 into para2;
  end $$
 
  create procedure proc2 (in para1 int , out para2 int)
  begin
      select para1 into para2;
  end $$
  delimiter ;
  注意, 新建過程之后,沒有對 li 帳號進行授權.
 
  這時執行程序如下
 
 
  import java.sql.CallableStatement;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.SQLException;
  import java.sql.Types;
 
  public class T {
      public static void main(String[] args) throws SQLException, ClassNotFoundException {
          Class.forName("com.mysql.jdbc.Driver");
          Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mvbox", "li", "li");
 
          CallableStatement cp = conn.prepareCall("{call proc1(?,?)}");
          cp.setInt(1, 1);
          cp.registerOutParameter(2, Types.INTEGER);
          cp.execute();
          System.out.println(cp.getInt(2));
          cp.close();
          conn.close();
      }
  }
 
  執行之后,結果如下:
  MySQL過程報 Parameter number N is not an OUT parameter錯誤
 
  增加如下授權之后,再次執行
  grant execute on procedure  mvbox.proc1 to  li@'localhost' identified by 'li';
 
  還是報錯,報錯信息如下:
  Exception in thread "main" java.sql.SQLException: User does not have access to metadata required to determine stored procedure parameter types. If rights can not be granted, configure connection with "noAccessToProcedureBodies=true" to have driver generate parameters that represent INOUT strings irregardless of actual parameter types.
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:997)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:983)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:928)
  at com.mysql.jdbc.DatabaseMetaData.getCallStmtParameterTypes(DatabaseMetaData.java:1858)
  at com.mysql.jdbc.DatabaseMetaData.getProcedureOrFunctionColumns(DatabaseMetaData.java:4508)
  at com.mysql.jdbc.JDBC4DatabaseMetaData.getProcedureColumns(JDBC4DatabaseMetaData.java:106)
  at com.mysql.jdbc.CallableStatement.determineParameterTypes(CallableStatement.java:857)
  at com.mysql.jdbc.CallableStatement.<init>(CallableStatement.java:630)
  at com.mysql.jdbc.JDBC4CallableStatement.<init>(JDBC4CallableStatement.java:46)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
  at com.mysql.jdbc.CallableStatement.getInstance(CallableStatement.java:524)
  at com.mysql.jdbc.ConnectionImpl.parseCallableStatement(ConnectionImpl.java:4335)
  at com.mysql.jdbc.ConnectionImpl.prepareCall(ConnectionImpl.java:4419)
  at com.mysql.jdbc.ConnectionImpl.prepareCall(ConnectionImpl.java:4393)
  at T.main(T.java:12)
 
  這個報錯信息就容易理解了,增加對proc表的select權限
  grant select on mysql.proc to li@'localhost' identified by 'li';
 
  再次執行,成功!!
 
  這時候,如果訪問proc2 過程,則報錯如下:(當然會出錯,因為沒有對帳號li進行授權啊)
  Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: execute command denied to user 'li'@'localhost' for routine 'mvbox.proc2'
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
  at com.mysql.jdbc.Util.getInstance(Util.java:383)
  at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1062)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
  at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
  at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
  at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
  at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840)
  at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
  at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1302)
  at com.mysql.jdbc.CallableStatement.execute(CallableStatement.java:921)
  at T.main(T.java:15)
 
  但是這個報錯,明確顯示了帳號li對于過程mvbox.proc2 沒有執行權限.這樣很容易定位解決問題.
 
  在什么情況下,會因為權限不足而報Parameter number N is not an OUT parameter的錯誤呢?
 
  就是該帳號沒有任何execute的授權,而執行存儲過程的時候,就會有上述報錯.
 
  并且僅僅是使用JDBC的途徑,如果使用MySQL 的客戶端,報錯信息也是明確的..

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌审旗| 大姚县| 无锡市| 富裕县| 安阳市| 鄂伦春自治旗| 澄迈县| 康乐县| 南岸区| 博客| 新安县| 图片| 塔城市| 台东市| 昌黎县| 丰宁| 江山市| 苍南县| 武乡县| 临澧县| 洮南市| 沅江市| 虹口区| 辉县市| 昌黎县| 芜湖市| 老河口市| 清河县| 抚顺县| 四会市| 泰宁县| 阿拉善右旗| 沙河市| 平阳县| 景德镇市| 伊金霍洛旗| 邹城市| 襄樊市| 托克逊县| 买车| 青神县|