getcustomermain.java
来自「噶额外噶外骨骼感广泛高热感 就 啊啊」· Java 代码 · 共 54 行
JAVA
54 行
package itso.storedproc.main;
import java.sql.*;
/**
* @author UELI
*
* To change this generated comment edit the template variable "typecomment":
* Window>Preferences>Java>Templates.
* To enable and disable the creation of type comments go to
* Window>Preferences>Java>Code Generation.
*/
public class GetCustomerMain {
private static final String DBCLASS = "COM.ibm.db2.jdbc.app.DB2Driver";
private static final String URL = "jdbc:db2:EJBBANK";
public GetCustomerMain() {
try {
Class.forName(DBCLASS);
} catch (Throwable ex) {}
}
private Connection getConnection() throws SQLException {
Connection con = DriverManager.getConnection(URL);
return con;
}
public static void main(String[] args) throws SQLException {
String customerID = "104";
if (args != null && args.length > 0) customerID = args[0];
GetCustomerMain custTest = new GetCustomerMain();
// connect to database
Connection con = custTest.getConnection();
// prepare statement that calls stored procedure
CallableStatement cs = con.prepareCall("{call ITSO.GetCustomer(?)} ");
cs.setString(1, customerID);
// execute
ResultSet rs = cs.executeQuery();
while (rs.next()) {
// get the data from the row
System.out.println("CUSTOMER ID: " + rs.getString("customerid"));
System.out.println("TITLE: " + rs.getString("title"));
System.out.println("FIRST NAME: " + rs.getString("firstname"));
System.out.println("LAST NAME: " + rs.getString("lastname"));
System.out.println("USERNAME: " + rs.getString("userid"));
System.out.println("PASSWORD: " +rs.getString("password"));
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?