MySQL存储过程实例
时间:2021-07-01 10:21:17
帮助过:25人阅读
com.itnba.maya.cunchu;
import java.util.*
;
import java.sql.*
;
public class Test {
public static void main(String[] args)
throws Exception{
String div="com.mysql.jdbc.Driver"
;
String url="jdbc:mysql://127.0.0.1:3306/mydb?characterEncoding=GBK"
;
String uid="root"
;
String pwd=""
;
Class.forName(div);
Connection conn =
DriverManager.getConnection(url,uid,pwd);
//CallableStatement stat = conn.prepareCall("call TCC()"); //调用没有参数的存储过程
//CallableStatement stat = conn.prepareCall("call TAA(?,?)");//调有参数的存储过程(输入参数)
//stat.setString(1, "k002");
//stat.setInt(2, 99);
CallableStatement stat = conn.prepareCall("call TDD(?,?)");
//调有参的存储过程(输出参数)
stat.setString(1, "k001"
);
stat.setInt(2,80
);
ResultSet rs =
stat.executeQuery();
while(rs.next()){
System.out.println(rs.getString(2
));
}
conn.close();
}
}
运行结果
菠萝
桔子
葡萄
樱桃
桃子
香蕉
草莓
对照fruit表
MySQL存储过程实例
标签:存储 .com sql存储过程 driver callable getc cut cal public