create procedure sp_name() begin ......... end
call sp_name()
drop procedure sp_name//
show procedure status
show create procedure sp_name
DROP TABLE IF EXISTS `cus_device`; CREATE TABLE `cus_device` ( `device_sn` varchar(20) NOT NULL COMMENT '设备编号', `device_cat_id` int(1) DEFAULT NULL COMMENT '设备类型', `device_name` varchar(64) DEFAULT NULL COMMENT '设备名称', `device_type` varchar(64) DEFAULT NULL COMMENT '设备型号', PRIMARY KEY (`device_sn`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP PROCEDURE IF EXISTS `countDevicesName`; DELIMITER ;; CREATE PROCEDURE `countDevicesName`(IN dName VARCHAR(12),OUT deviceCount INT) BEGIN SELECT COUNT(*) INTO deviceCount FROM cus_device WHERE device_name = dName; END ;; DELIMITER ;
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC
"-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 打印查询语句 -->
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
<!-- 配置别名 -->
<typeAliases>
<typeAlias type="com.lidong.axis2demo.DevicePOJO" alias="DevicePOJO" />
</typeAliases>
<!-- 配置环境变量 -->
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://127.0.0.1:3306/bms?characterEncoding=GBK" />
<property name="username" value="root" />
<property name="password" value="123456" />
</dataSource>
</environment>
</environments>
<!-- 配置mappers -->
<mappers>
<mapper resource="com/lidong/axis2demo/DeviceMapper.xml" />
</mappers>
</configuration>
public class DevicePOJO{
private String devoceName;//设备名称
private String deviceCount;//设备总数
public String getDevoceName() {
return devoceName;
}
public void setDevoceName(String devoceName) {
this.devoceName = devoceName;
}
public String getDeviceCount() {
return deviceCount;
}
public void setDeviceCount(String deviceCount) {
this.deviceCount = deviceCount;
}
}
package com.lidong.axis2demo;
public interface DeviceDAO {
/**
* 调用存储过程 获取设备的总数
* @param devicePOJO
*/
public void count(DevicePOJO devicePOJO);
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lidong.axis2demo.DeviceDAO">
<resultMap id="BaseResultMap" type="CusDevicePOJO">
<result column="device_sn" property="device_sn" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List">
device_sn, device_name,device_mac
</sql>
<select id="count" parameterType="DevicePOJO" useCache="false"
statementType="CALLABLE">
<![CDATA[
call countDevicesName(
#{devoceName,mode=IN,jdbcType=VARCHAR},
#{deviceCount,mode=OUT,jdbcType=INTEGER});
]]>
</select>
</mapper>
package com.lidong.axis2demo;
import java.io.IOException;
import java.io.Reader;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
/**
* MyBatis 执行存储过程
* @author Administrator
*
*/
public class TestProduce {
private static SqlSessionFactoryBuilder sqlSessionFactoryBuilder;
private static SqlSessionFactory sqlSessionFactory;
private static void init() throws IOException {
String resource = "mybatis-config.xml";
Reader reader = Resources.getResourceAsReader(resource);
sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
sqlSessionFactory = sqlSessionFactoryBuilder.build(reader);
}
public static void main(String[] args) throws Exception {
testCallProduce();
}
/**
* @throws IOException
*/
private static void testCallProduce() throws IOException {
init();
SqlSession session= sqlSessionFactory.openSession();
DeviceDAO deviceDAO = session.getMapper(DeviceDAO.class);
DevicePOJO device = new DevicePOJO();
device.setDevoceName("设备名称");
deviceDAO.count(device);
System.out.println("获取"+device.getDevoceName()+"设备的总数="+device.getDeviceCount());
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有