简体   繁体   中英

How create Web Services on AS400 JDE and consume them in Netbeans Java

My problem is that I don't know how access the data from my java application. I am using netbeans 6.9.1 and I created already a connection with AS400 using jdbc:as400://DBase... I tried to create Stored Procedures or create Web Services to consume them from my java application, but I couldn't. Also, I tried to create Entities Classes from Database but AS400 database has not primary keys. Any idea how I can use this database in my java application? Thank a lot!!!

Hi @hetch those something steps for create WEB SERVICES on AS/400 databases and WSDL file exposed. :)

  1. Create a DataSource

     public DataSource getDataSource(String bd) throws Exception { DataSource ds = null; try { if(bd.trim().equals("as400")) { ds = (DataSource) ic.lookup("jdbc/your_name_jndi"); } return ds; } catch(NamingException n) { throw new Exception("Err getDataSource NamingException - " + n.getMessage()); } } 
  2. Create your Bean's

  3. Create a Connection to database UPDATE --This class you can to connect to databases whatever, ie (ORACLE, MYSQL, SQL-SERVER, etc, etc).--

     public class DataBases { public static Connection con = null; static public ServiceLocator locator; public DataBases() throws Exception { super(); } public Connection getConexionAS400() { try { con = locator.getDataSource("AS/400").getConnection(); System.out.println("CONECCTED AS/400 DB. " + con); } catch(Exception e) { e.printStackTrace(); } return con; } } public final class ServiceLocator { private static ServiceLocator pcf; private static InitialContext ic; /**. * Context initialize. * @throws Exception */ private ServiceLocator() throws Exception { try { ic = new InitialContext(); } catch (NamingException n) { throw new Exception( "Err InitialContext (ServiceLocator) NamingException - " + n.getMessage()); } } /**. * Generate instance servicelocator * @return service locator * @throws Exception */ public static ServiceLocator getInstance() throws Exception { if(pcf == null) { synchronized (ServiceLocator.class) { pcf = new ServiceLocator(); } } return pcf; } /**. * * @param dsName Nombre del jdbc * @return DataSource * @throws Exception */ public DataSource getDataSource(String bd) throws Exception { DataSource ds = null; try { if(bd.trim().equals("as400")) { ds = (DataSource) ic.lookup("jdbc/tiempoaire1"); } return ds; } catch(NamingException n) { throw new Exception( "Err getDataSource (ServiceLocator) NamingException - " + n.getMessage()); } } } 
  4. Create classes to CRUD to database, in this step you will have know ID tables on CRUD works.

That's it !!!

I hope help you. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM