package cn.nagasoft.cms.total.action;
?
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
?
?
public class T {
public static Connection getConnection() throws ClassNotFoundException, SQLException{
String url="jdbc:mysql://localhost:3306/cloud_record";
Class.forName("com.mysql.jdbc.Driver");
String a="root";String b="root";
Connection con=DriverManager.getConnection(url,a,b);
return con;
}
?
/**
* @param args
*/
public static void main(String[] args) {
? ?String sql = "{call firstPro(?,?)}";
? ?//获得连接
? ?Connection conn = null;
? ?CallableStatement stmt = null;
? ?//构造语句对象,传递过程及参数,返回结果
? ?try{
? ? ?conn = T.getConnection();// 工具类获得连接
? ? ?stmt = conn.prepareCall(sql);
? ? ?//输入参数,
? ? ?stmt.setInt(1, 1);
? ? ?//执行
? ? ?stmt.execute();
? ? ?//取出过程运行的结果,指定输出参数的位置
// ? ? ?String in = stmt.getString(1);
? ? ?String name = stmt.getString(2);
// ? ? ?System.out.println(in);
? ? ?System.out.println(name);
? ?}catch(Exception e){
? ? ?e.printStackTrace();
? ?}finally{
? ?//关闭资源
}
?
}
?
}
?