zoukankan      html  css  js  c++  java
  • java调用存储过程mysql

          在java中调用带返回值的存储过程的实现

    直接上代码:

                

    DELIMITER $$
    
    CREATE
        /*[DEFINER = { user | CURRENT_USER }]*/
        PROCEDURE `test`.`text_e`(IN param1 INT ,OUT param2 VARCHAR(20))
        /*LANGUAGE SQL
        | [NOT] DETERMINISTIC
        | { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
        | SQL SECURITY { DEFINER | INVOKER }
        | COMMENT 'string'*/
        BEGIN
    		SELECT user_name INTO param2 FROM USER WHERE user_id=param1;
        END$$
    
    DELIMITER ;
    

      java代码:

      

    public static String getUserNameById(int id){
    		Connection con = BaseDao.getConnection();
    		CallableStatement proc = null;
    		try {
    			proc = con.prepareCall("{call text_e(?,?)}");
    			proc.setInt(1, id);//输入
    			proc.registerOutParameter(2, Types.VARCHAR);//输出
    			proc.execute();
    			return proc.getString(2);
    		} catch (SQLException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}finally {
    			try {
    				proc.close();
    				con.close();
    			} catch (SQLException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		
    		
    		return null;
    		
    		
    	}
    

      

  • 相关阅读:
    Design Pattern
    javascript summary
    nodejs template
    MVC---Case 1
    About js
    本地schemeApp扩展
    BNU4208:Bubble sort
    [置顶] think in java interview-高级开发人员面试宝典代码示例
    java+socket 简易聊天工具
    oracle 字段自增 两段代码搞定
  • 原文地址:https://www.cnblogs.com/airycode/p/4822450.html
Copyright © 2011-2022 走看看