a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 155|回复: 0

[专业语言] Java认证辅导之关于java调用的存贮过程

[复制链接]
发表于 2012-8-4 12:44:44 | 显示全部楼层 |阅读模式
Java认证辅导之关于java调用的存贮过程
7 I7 a& J9 H# A( t; m1 U1 Jjava调用存贮过程
0 I  R3 C8 o- Cpublic void testProc(){
" g$ J& b( J7 V" `  p: Q, b. b6 ]Connection conn = getConnection();4 f/ S1 n$ y5 S+ g! u: v# Q& \: J2 D
CallableStatement stmt = null;
1 e* |* s/ B) L9 f" K& wtry{+ n: g9 |( B) j+ ]# c# ^, y0 y
stmt = conn.prepareCall(“{call mappingProc(?)}”);2 J5 u9 c6 }/ m
stmt.registerOutParameter(1, Types.INTEGER);
3 n0 m& _. p- |% Bstmt.execute();
$ G! e* n% `6 f7 a% H3 \% |int i= stmt.getInt(1);: ]# X" y' q! m1 a- N) q" e
System.out.println(“count = ” + i);& m; F+ A# }( ~- v( v4 S/ D9 q7 C
}catch(Exception e){
8 o/ j. ?' k: ~1 q: sSystem.out.println(“hahad = ”+e.toString());
' ~3 J" B+ \& T# E3 X( f3 Y% d9 W( t}finally{. x+ Z- C% |) X$ E
try {
0 d0 Z" F4 e5 `! D9 o4 bstmt.close();
* @+ N5 n  D, g& j3 _: kconn.close();
8 ~# X6 c0 y: ?: I8 a}catch (Exception ex) {
! w9 V# M6 O+ F4 c+ HSystem.out.println(“ex : ”+ ex.getMessage());
5 T) N6 V6 E, Z5 Z* a}
2 G& R2 z  D6 U9 J5 C' L2 p}
) v% _5 p0 G$ R1 T1 L}+ R1 Q' d' C# ^: }
package yicha.cigan.ren;
% C# M0 J. w8 A) A: i! S8 Wimport java.sql.CallableStatement;
9 Y6 u6 M, D) Y1 j: ^- ]import java.sql.Connection;
; q0 ~6 V- ?! c6 c! himport java.sql.DriverManager;2 }% {) Y- c- K/ y- e) H
import java.sql.Date;7 y/ R1 z9 l- R# v" k5 V
import java.sql.PreparedStatement;2 K  r/ r1 j9 A# ~% `9 K; o
public class CallProdure {5 [, t( D6 u8 o  K- @' _2 e
/*** n3 r# v0 o3 ?; J0 [
* @param args! _7 d1 @1 p7 ~, q2 X' J
* @throws ClassNotFoundException$ @! L& K" X3 ^4 X( l: i
*/8 V" v8 U2 ^: l8 I; V- F
public static void main(String[] args) throws ClassNotFoundException {
( s3 s) A, a- o6 t$ j& M1 T// TODO Auto-generated method stub6 y0 _% q" h. h& A/ `. \& ]
Class.forName(“net.sourceforge.jtds.jdbc.Driver”);
* d7 j) w+ Q0 r" Y* pString url=“jdbc:jtds:sqlserver://192.168.1.181:1433/JPPic;user=sa;password=1234”;
4 e9 J% c& Y( `2 @- J9 i7 jString sql = “{ call InsertUser(?,?)}”;
/ z7 g4 f4 V  eConnection cn = null;
5 O" r! G" s9 \  i: ^( g8 @CallableStatement cmd = null;5 E8 E  i. ~# O- W
try
* v9 H8 z( I( N% o# m+ a& r* |7 _# ?) _{. b* _6 t% i: B8 m5 f
cn = DriverManager.getConnection(url);/ Z6 u6 c1 C0 B4 W: j! @
// PreparedStatement pre =cn.prepareStatement(“Exec InsertUser ?,?”);7 G; ?- H% q' w# @: K; ?
// pre.setString(1, “renyiyong”);
0 p2 k! s9 Y6 u3 T8 A- t// pre.setString(2, “liuguanzhang”);5 {& v+ Q- Z! `$ n# N; R
// pre.execute();
' O* a7 s; ]$ p6 Y! H3 Ocmd = cn.prepareCall(sql);- R, c7 g5 \" v) H! e
cmd.setString(1, “zhongguo”);7 Y/ t, {" y( S4 r0 {
cmd.setString(2, “meiguo”);
. r( E( B5 X7 D7 a2 F7 D$ P$ r2 ]8 K$ ?

* e* ~( b0 a$ ]0 X' Qcmd.execute();- ?. f1 r. w" q/ ]; r
}catch(Exception ex)6 i0 x2 \8 X9 o; I+ h
{
% k# V5 u4 _" X$ y/ j: @System.out.println(ex.getLocalizedMessage());: w  Y! \$ B6 A- C# ?
}finally4 a% t7 w0 E( ~! v/ e3 m- ~0 c
{$ |$ U9 r) C! D; Q; a% d+ {/ a9 |" J
try
8 A% L9 p/ K% A4 \{) @6 q! Z% d- D" R  G
if(cn != null)
0 c) F: L1 Y; G' L' L8 j{
* k, \- w1 F: Tcn.close();
' V% {) U9 i: e! A: f  ~9 Ccn = null;
/ G3 N; @8 P" J}
. a' e5 D0 |, l: e  S}catch(Exception e){}; n) C, c& ?; p0 Z% I7 O* g" V$ \
}
1 T6 O; M5 I# u/ t1 x' I}
- w$ F8 n0 R' q9 C  r9 t}. k; f& Z* K# b- C
private int UpdateImg( ImageStore img ){, R/ x1 G, b! b6 A* d
/**
5 L6 W3 m/ y2 Q5 ECREATE PROCEDURE [convertImgStoreUpdate] @width int ,@high int ,@typeflag2 tinyint,@ActualHeight int ,@ActualWidth int ,@OriginalSize bigint,1 P! j6 B) r1 B" e! C
@SmallJpgSize bigint,@SmallJpgHeight int,@SmallJpgWidth int,
, y7 P* A- @; M5 [$ w7 b( w8 u6 M@SmallGifSize bigint,@SmallGifHeight int,@SmallGifWidth int,6 i' n3 t! S" V; i9 C
@BigGifSize bigint,@BigGifHeight int,@BigGifWidth int,
, _/ z( d- J1 A8 N# x) @@BigJpgSize bigint,@BigJpgHeight int,@BigJpgWidth int,
6 J! i, ^( |& T* c! t( L' [- Q@ThumbGifSize bigint,@ThumbJpgSize bigint,, I' x, J; A! k. ?5 d- t: R/ |
@url nvarchar(4000)) h8 w5 X( x# D" w/ g$ z! {1 C
AS$ C" @/ H. K# a  j
update imgStore set Haslarge=1,Width=@width,High=@high,Fetchflag=2,typeflag=@typeflag2, Actual_Height=@ActualHeight ,Actual_Width=@ActualWidth, Original_Size=@OriginalSize
4 E! O+ V& r' y4 o,SmallJpgSize=@SmallJpgSize,SmallJpgHeight=@SmallJpgHeight,SmallJpgWidth=@SmallJpgWidth
  Q$ J$ a" ^, W,SmallGifSize=@SmallGifSize,SmallGifHeight=@SmallGifHeight,SmallGifWidth=@SmallGifWidth
3 u  c( L; j& H3 ?,BigGifSize=@BigGifSize,BigGifHeight=@BigGifHeight,BigGifWidth=@BigGifWidth! a4 A1 z5 W! |0 }! i
,BigJpgSize=@BigJpgSize,BigJpgHeight=@BigJpgHeight,BigJpgWidth=@BigJpgWidth7 v5 x: f2 }) }2 w: k3 l
,ThumbGifSize=@ThumbGifSize,ThumbJpgSize=@ThumbJpgSize) f$ C. Q$ W7 [1 i- ?
where url=@url" T% `3 n3 `; M
GO
( A6 j9 l8 ]! b*/
4 N3 p8 u* x6 b$ Y- H$ R1 z- R  Ktry {
' F+ \% x# G# }# @5 Dlock.lock();
. I. Z8 F' X, T2 A- x% E! M6 sPreparedStatement pre = getConnection().prepareStatement(“Exec convertImgStoreUpdate2 ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?”);+ g5 V' f) g8 @# W0 ?' U/ d2 e
pre.setInt(1,img.getFetchflag().intValue());$ O# f7 z0 x1 N& ?. L: u* S' a
pre.setInt(2,img.getHas176().intValue());
' w: [- t5 k! Rpre.setInt(3,img.getHas240().intValue());
) z& M6 Z) }; o1 w$ @0 opre.setInt(4,img.getTypeflag().intValue());
/ n' }# T3 B/ V6 \$ ipre.setInt(5,img.getJpgWsrc().intValue());
7 M  l) Y% j0 k9 Z: \pre.setLong(6,img.getJpgHsrc().intValue());% Y/ ~1 n" n+ v2 K# R' o% u
pre.setLong(7,img.getJpgSsrc().longValue());0 w. M& n4 {" j: ~" S* d
pre.setInt(8,img.getGifS100().intValue());
4 E  x2 M6 g6 J* Qpre.setInt(9,img.getGifH100().intValue());) x9 U6 |- G% p0 C$ ?
pre.setLong(10,img.getGifW100().longValue());3 L) I, @1 B6 e6 D- ^
pre.setInt(11,img.getJpgS100().intValue());3 p; f( x) q* A0 |  p  `. h; W% |' @
pre.setInt(12,img.getJpgH100().intValue());
4 ?( p: x- l3 B7 x  T8 Dpre.setLong(13,img.getJpgW100().longValue());3 a8 Z1 P9 [% n, G
pre.setInt(14,img.getGifS128().intValue());8 o0 ?% D; a2 v. c1 [- ^
pre.setInt(15,img.getGifH128().intValue());
8 n9 Y$ ?" m; M* f6 ]% bpre.setLong(16,img.getGifW128().longValue());
: u0 k& \5 }, D) _' H2 G# `: @: J9 U! L1 q$ C* V% `2 L' A8 o

( f+ b2 b5 m8 R! j, t% kpre.setInt(17,img.getJpgS128().intValue());$ h, ]1 H4 c4 o5 J) M' @3 j
pre.setInt(18,img.getJpgH128().intValue());
9 n% j, r$ I1 D. h6 Dpre.setLong(19,img.getJpgW128().longValue());2 \% D2 w) e' N3 T5 E, b) w
pre.setInt(20,img.getGifS176().intValue());
8 a" n8 |* P. Epre.setInt(21,img.getGifH176().intValue());
( ^- c' {3 H) U) Y: ]+ E* Y' ?2 upre.setLong(22,img.getGifW176().longValue());" i$ P1 V+ {/ ^" w3 Z9 j1 P2 G
pre.setInt(23,img.getJpgS176().intValue());+ j* `) H) W& e* L* V
pre.setInt(24,img.getJpgH176().intValue());
4 _) a6 _# u  ]/ G" X- `. Fpre.setLong(25,img.getJpgW176().longValue());
- N. }' f! Y) C8 ?$ u3 @- ?: y9 l. Gpre.setInt(26,img.getGifS240().intValue());3 i8 [3 l, b5 J) X" f
pre.setInt(27,img.getGifH240().intValue());: t* X; Z; D( c' b# n% D! U
pre.setLong(28,img.getGifW240().longValue());+ R! x- e6 }' V% I
pre.setInt(29,img.getJpgS240().intValue());
0 N& s# y2 i! N3 Cpre.setInt(30,img.getJpgH240().intValue());/ U) J6 I! V8 t* G6 F5 k4 W
pre.setLong(31,img.getJpgW240().longValue());4 M2 @' I9 Z+ o( F* g" ~$ r
// pre.setInt(14,img.getGifH176().intValue());
: K' ]+ {* k" w5 D- o// pre.setInt(15,img.getGifW176().intValue());
- d8 L. ~# R; T//' ]" L5 d3 A' l7 l
// pre.setLong(16,img.getJpgS176().longValue());
4 R9 m- ?& f, K2 c. E7 v& s) u// pre.setInt(17,img.getJpgH176().intValue());8 Z" D/ P( }$ I+ t
// pre.setInt(18,img.getJpgW176().intValue());
9 U, B( A% w; B# p0 p: y//
# E# _3 r: l* Z  U3 r1 q5 W// pre.setLong(19,img.getGifS100().longValue());2 F$ i+ K3 f. I7 b# X# T2 U; ~
// pre.setLong(20,img.getJpgS100());# Y' U2 A8 c0 y& m( m
//; W: T. k; }( D  Y# X! M6 m& V
pre.setInt(32,img.getId());
- S4 K; W0 b) x; Kreturn pre.executeUpdate();
& D  _5 ^4 o5 o; D$ {9 Z1 m7 u% X% z} catch (Exception e) {( |9 e2 j- l4 D5 n6 k! p
// TODO Auto-generated catch block
9 l8 ]0 i# y  [/ ~& u1 pe.printStackTrace();. f3 ]2 n, D0 b" E7 t
} finally {
2 U: a: z2 Q4 X& v. Z' vlock.unlock();
+ P0 I1 o# P+ p3 C}
! C( p8 [; N8 t  f1 I/ s$ jreturn 0;
, A" }. M# ?5 |" W2 O, z. F7 C}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-9-27 23:49 , Processed in 0.246576 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表