会计考友 发表于 2012-8-4 12:44:44

Java认证辅导之关于java调用的存贮过程

Java认证辅导之关于java调用的存贮过程
java调用存贮过程
public void testProc(){
Connection conn = getConnection();
CallableStatement stmt = null;
try{
stmt = conn.prepareCall(“{call mappingProc(?)}”);
stmt.registerOutParameter(1, Types.INTEGER);
stmt.execute();
int i= stmt.getInt(1);
System.out.println(“count = ” + i);
}catch(Exception e){
System.out.println(“hahad = ”+e.toString());
}finally{
try {
stmt.close();
conn.close();
}catch (Exception ex) {
System.out.println(“ex : ”+ ex.getMessage());
}
}
}
package yicha.cigan.ren;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Date;
import java.sql.PreparedStatement;
public class CallProdure {
/**
* @param args
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws ClassNotFoundException {
// TODO Auto-generated method stub
Class.forName(“net.sourceforge.jtds.jdbc.Driver”);
String url=“jdbc:jtds:sqlserver://192.168.1.181:1433/JPPic;user=sa;password=1234”;
String sql = “{ call InsertUser(?,?)}”;
Connection cn = null;
CallableStatement cmd = null;
try
{
cn = DriverManager.getConnection(url);
// PreparedStatement pre =cn.prepareStatement(“Exec InsertUser ?,?”);
// pre.setString(1, “renyiyong”);
// pre.setString(2, “liuguanzhang”);
// pre.execute();
cmd = cn.prepareCall(sql);
cmd.setString(1, “zhongguo”);
cmd.setString(2, “meiguo”);


cmd.execute();
}catch(Exception ex)
{
System.out.println(ex.getLocalizedMessage());
}finally
{
try
{
if(cn != null)
{
cn.close();
cn = null;
}
}catch(Exception e){}
}
}
}
private int UpdateImg( ImageStore img ){
/**
CREATE PROCEDURE [convertImgStoreUpdate] @width int ,@high int ,@typeflag2 tinyint,@ActualHeight int ,@ActualWidth int ,@OriginalSize bigint,
@SmallJpgSize bigint,@SmallJpgHeight int,@SmallJpgWidth int,
@SmallGifSize bigint,@SmallGifHeight int,@SmallGifWidth int,
@BigGifSize bigint,@BigGifHeight int,@BigGifWidth int,
@BigJpgSize bigint,@BigJpgHeight int,@BigJpgWidth int,
@ThumbGifSize bigint,@ThumbJpgSize bigint,
@url nvarchar(4000)
AS
update imgStore set Haslarge=1,Width=@width,High=@high,Fetchflag=2,typeflag=@typeflag2, Actual_Height=@ActualHeight ,Actual_Width=@ActualWidth, Original_Size=@OriginalSize
,SmallJpgSize=@SmallJpgSize,SmallJpgHeight=@SmallJpgHeight,SmallJpgWidth=@SmallJpgWidth
,SmallGifSize=@SmallGifSize,SmallGifHeight=@SmallGifHeight,SmallGifWidth=@SmallGifWidth
,BigGifSize=@BigGifSize,BigGifHeight=@BigGifHeight,BigGifWidth=@BigGifWidth
,BigJpgSize=@BigJpgSize,BigJpgHeight=@BigJpgHeight,BigJpgWidth=@BigJpgWidth
,ThumbGifSize=@ThumbGifSize,ThumbJpgSize=@ThumbJpgSize
where url=@url
GO
*/
try {
lock.lock();
PreparedStatement pre = getConnection().prepareStatement(“Exec convertImgStoreUpdate2 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?”);
pre.setInt(1,img.getFetchflag().intValue());
pre.setInt(2,img.getHas176().intValue());
pre.setInt(3,img.getHas240().intValue());
pre.setInt(4,img.getTypeflag().intValue());
pre.setInt(5,img.getJpgWsrc().intValue());
pre.setLong(6,img.getJpgHsrc().intValue());
pre.setLong(7,img.getJpgSsrc().longValue());
pre.setInt(8,img.getGifS100().intValue());
pre.setInt(9,img.getGifH100().intValue());
pre.setLong(10,img.getGifW100().longValue());
pre.setInt(11,img.getJpgS100().intValue());
pre.setInt(12,img.getJpgH100().intValue());
pre.setLong(13,img.getJpgW100().longValue());
pre.setInt(14,img.getGifS128().intValue());
pre.setInt(15,img.getGifH128().intValue());
pre.setLong(16,img.getGifW128().longValue());


pre.setInt(17,img.getJpgS128().intValue());
pre.setInt(18,img.getJpgH128().intValue());
pre.setLong(19,img.getJpgW128().longValue());
pre.setInt(20,img.getGifS176().intValue());
pre.setInt(21,img.getGifH176().intValue());
pre.setLong(22,img.getGifW176().longValue());
pre.setInt(23,img.getJpgS176().intValue());
pre.setInt(24,img.getJpgH176().intValue());
pre.setLong(25,img.getJpgW176().longValue());
pre.setInt(26,img.getGifS240().intValue());
pre.setInt(27,img.getGifH240().intValue());
pre.setLong(28,img.getGifW240().longValue());
pre.setInt(29,img.getJpgS240().intValue());
pre.setInt(30,img.getJpgH240().intValue());
pre.setLong(31,img.getJpgW240().longValue());
// pre.setInt(14,img.getGifH176().intValue());
// pre.setInt(15,img.getGifW176().intValue());
//
// pre.setLong(16,img.getJpgS176().longValue());
// pre.setInt(17,img.getJpgH176().intValue());
// pre.setInt(18,img.getJpgW176().intValue());
//
// pre.setLong(19,img.getGifS100().longValue());
// pre.setLong(20,img.getJpgS100());
//
pre.setInt(32,img.getId());
return pre.executeUpdate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
lock.unlock();
}
return 0;
}
页: [1]
查看完整版本: Java认证辅导之关于java调用的存贮过程