📄 customercontrollertestclient.java~1~
字号:
package bookstore;import javax.naming.*;import java.util.*;import javax.rmi.PortableRemoteObject;import java.sql.*;public class CustomerControllerTestClient extends Object { private CustomerControllerHome customerControllerHome = null; private CustomerController customerController = null; java.util.Date utilDate = new java.util.Date();// Convert it to java.sql.Date java.sql.Date date = new java.sql.Date(utilDate.getTime()); //Construct the EJB test client public CustomerControllerTestClient() { initialize(); } public void initialize() { try { //get naming context Context context = getInitialContext(); //look up jndi name Object ref = context.lookup("CustomerController"); //look up jndi name and cast to Home interface customerControllerHome = (CustomerControllerHome) PortableRemoteObject.narrow(ref, CustomerControllerHome.class); customerController = customerControllerHome.create(); /*CustomerDetails customerValue=new CustomerDetails("","Samson","Samxjsh", "@a",1,date,"北京","学生","441322198109193832","北京信息工程学院", "100101","010-64885499","xiejiansheng@mail.biti.edu.cn",0); customerController.createCustomer(customerValue);*/ CustomerDetails customerValue=customerController.getCustomerByAccount("Samxjsh"); System.out.println(customerValue.getCustomerID()); System.out.println(customerValue.getEmail()); } catch(Exception e) { e.printStackTrace(); } } private Context getInitialContext() throws Exception { System.out.println("TestClient getInitialContext"); String url = "t3://samson:7001"; String user = "weblogic"; String password = "weblogic"; Properties properties = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); } System.out.println("getInitialContext out"); return new InitialContext(properties); } catch(Exception e) { throw e; } }//getInitailContext //---------------------------------------------------------------------------- // Methods that use Home interface methods to generate a Remote interface reference //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // Methods that use Remote interface methods to access data through the bean //---------------------------------------------------------------------------- public String createCustomer(CustomerDetails customerValue) { String returnValue = ""; if (customerController == null) { System.out.println("Error in createCustomer(): customerController is null" ); return returnValue; } try { returnValue = customerController.createCustomer(customerValue); } catch(Exception e) { e.printStackTrace(); } return returnValue; } //Main method public static void main(String[] args) { CustomerControllerTestClient client = new CustomerControllerTestClient(); // Use the client object to call one of the Home interface wrappers // above, to create a Remote interface reference to the bean. // If the return value is of the Remote interface type, you can use it // to access the remote interface methods. You can also just use the // client object to call the Remote interface wrappers. }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -