01.
package
com.java.myapp;
02.
03.
import
java.sql.CallableStatement;
04.
import
java.sql.Connection;
05.
import
java.sql.DriverManager;
06.
import
java.sql.SQLException;
07.
import
java.sql.Types;
08.
09.
public
class
MyClass {
10.
11.
public
static
void
main(String[] args) {
12.
13.
Connection connect =
null
;
14.
15.
try
{
16.
Class.forName(
"com.microsoft.sqlserver.jdbc.SQLServerDriver"
);
17.
connect = DriverManager.getConnection(
""
+
19.
20.
21.
String command =
"EXEC insertCustomer ?,?,?,?,?,?,?,?"
;
22.
CallableStatement stmt = connect.prepareCall (command);
23.
24.
25.
String strCustomerID =
"C005"
;
26.
String strName =
"Fun Wipa"
;
27.
String strEmail =
"fun.wipa@thaicreate.com"
;
28.
String strCountryCode =
"TH"
;
29.
Double dBudget =
100000.00
;
30.
Double dUsed =
0.00
;
31.
32.
stmt.setString(
1
, strCustomerID);
33.
stmt.setString(
2
, strName);
34.
stmt.setString(
3
, strEmail);
35.
stmt.setString(
4
, strCountryCode);
36.
stmt.setDouble(
5
, dBudget);
37.
stmt.setDouble(
6
, dUsed);
38.
stmt.registerOutParameter(
7
, Types.INTEGER);
39.
stmt.registerOutParameter(
8
, Types.VARCHAR);
40.
41.
42.
stmt.execute();
43.
44.
45.
Integer pResult = stmt.getInt(
7
);
46.
System.out.println(
"pResult : "
+ pResult.toString());
47.
48.
49.
String pMessage = stmt.getString(
8
);
50.
System.out.println(
"pMessage : "
+ pMessage);
51.
52.
53.
}
catch
(Exception e) {
54.
55.
e.printStackTrace();
56.
}
57.
58.
try
{
59.
connect.close();
60.
}
catch
(SQLException e) {
61.
62.
e.printStackTrace();
63.
}
64.
65.
}
66.
67.
}