Java JDBC connectedness to DB2 AS400 database example

To brand a connectedness to DB2 on AS400 using JDBC nosotros quest the next values

  • Host Name or IP Address of The Machine
  • User Id
  • Password

Instead of putting the values correct into the plan its improve to soft code them using a properties file.

Sample properties file for JDBC connectedness mydb2.properties

#I-series ip or host mention local_system=XXX.XXX.XXX.XXX  #I-series UserId, used for login together with library listing userId=XXXXXXX   #I-series Password password=XXXXXXX 

Sample coffee plan for JDBC connection

static Properties props;  endeavour {   props = novel Properties();  props.load(new FileInputStream("properties/mydb2.properties"));   String DRIVER = "com.ibm.as400.access.AS400JDBCDriver";   String URL = "jdbc:as400://" + props.getProperty("local_system").trim() + ";naming=system;errors=full";  Connection conn = null;   //Connect to iSeries   Class.forName(DRIVER);   conn = DriverManager.getConnection(URL, props.getProperty("userId").trim(), props.getProperty("password").trim());    conn.close();  } grab (Exception e) {  System.out.println(e); } 

You quest the jt400.jar inwards your classpath for the project. You tin extract a re-create from the iSeries IFS directory.
/QIBM/ProdData/HTTP/Public/jt400/lib/jt400.jar

Hosting Unlimited Indonesia


Sumber http://www.mysamplecode.com/