JAVA调用MYSQL存储过程
JAVA调用MYSQL存储过程
工程视图:
代码清单:
myconn.java
package org.apache.sh_mysql.test;
import java.sql.*;
public class MyConn {
private static final String DRIVER = "com.mysql.jdbc.Driver";
private static final String URL = "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK";
private static final String USER = "root";
private static final String PASSWORD ="root";
static {
try {
Class.forName(DRIVER);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取连接
*
* @return
* @throws Exception
*/
public Connection getConnection() throws Exception {
return DriverManager.getConnection(URL, USER, PASSWORD);
}
/**
* 释放资源
*
* @param rs
* @param statement
* @param conn
*/
public void close(ResultSet rs, CallableStatement stmt, Connection conn) {
try{
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
}catch(Exception e){
e.printStackTrace();
}
}
}
代码清单:
mytest.java
package org.apache.sh_mysql.test;
import java.sql.*;
public class MyTest {
MyConn c=new MyConn();
public void handleData() {
try {
Connection conn=c.getConnection();
CallableStatement call=conn.prepareCall("{call pro_stu_count(?)}");
call.registerOutParameter(1, Types.INTEGER);
call.execute();
int count=call.getInt(1);
System.out.println(count);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void main(String[] args) {
MyTest t=new MyTest();
t.handleData();
}
}
相关文档:
觉得留言很有道理,文章很哲理,一并转载 建议读者看原文地址
作者: 阮一峰
日期: 2008年12月 7日
下面的文章是More Joel on Software一书的第8篇。
我觉得翻译难度很大,整整两个工作日,每天8小时以上,才译出了5000字。除了Joel大量使用俚语,另一个原因是原文涉及"编程原理",好多东西我根本不懂。希 ......
2008-04-26 09:25 作者:superman 来源:赛迪网
[摘要] 首先,本文的目标读者是正在从事技术工作的架构师。避免讲述一些陈腐的最佳实践,例如"日常构建(build daily)"、"测试一切(test everything)"和"经常集成( integrate often)。 任何具有称职架构师的项目都有分工明确的、定义良好的团队结构。他们还为进行编 ......
1. Multiply-Thread
Locks offer two primary features: mutual exclusion and visibility. Mutual exclusion means only one thread at a time may hold a given lock, so only one thread at a time will be using the shared data. Visibility is to ensure that changes made to shared data prior to releasing a lo ......
代码如下:
package com.test.j2se;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
/**数据加密
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
MessageDigest code = MessageD ......
XML文件实例:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource auth="Container" maxActive="20" name="sss" password="123"
type="javax.sql.DataSource" />
<Resource auth="Container" ......