Accéder au contenu principal

Accéder à une base de données AS400 depuis une application Spring Boot

Il est très simple d'accéder à un AS400 depuis une application Spring Boot (ou n'importe quelle application Java). Cela permet d'utiliser un ORM (Hibernate) ou d’exécuter des scripts AS400 à distance.

Dans le pom.xml, ajouter la dépendance JT400 :
<!-- https://mvnrepository.com/artifact/net.sf.jt400/jt400 -->
<dependency>
    <groupId>net.sf.jt400</groupId>
    <artifactId>jt400</artifactId>
    <version>6.6</version>
</dependency>

Dans application.properties, définir l'accès vers le serveur :
spring.datasource.url=jdbc:as400://NOM_DU_SERVEUR/BIB_PAR_DEFAUT;transaction isolation=none
spring.datasource.username=LOGIN
spring.datasource.password=PASSWORD
spring.datasource.driver-class-name=com.ibm.as400.access.AS400JDBCDriver

On précise le nom ou l'adresse IP du serveur, la bibliothèque à utiliser par défaut. 
Transaction isolation=none permet de ne pas gérer les transactions, et donc de pouvoir écrire dans fichiers AS400 qui ne sont pas journalisés. Sans cette option, il faut activer les journaux sur les fichiers.
Ensuite on précise le login et mot de passe de connexion et le driver.

Cette connexion s'utilise comme n'importe quelle connexion JDBC :
(1) Soit directement avec le composant JdbcTemplate :
@Autowired
private JdbcTemplate jdbcTemplate;
...
Integer jourMax = jdbcTemplate.queryForObject("select max(POLMP) from CTRLT", Integer.class);

(2) Soit en utilisant un mapping Hibernate :
@Entity
@Table(name = "MVTVARD")
public class Declaration {

  @Id
  private String id;

  @Column(name = "ARTI")
  private String article;
...

Ici la classe Declaration sera mappée sur la table / fichier MVTVARD et la colonne ARTI sera mappée sur l'attribut ARTI.

Commentaires

  1. 1xbet | Vie Casino
    1XBET is a global, 1xbet licensed and regulated online casino that has ボンズ カジノ been in existence since 2004, delivering quality casino games, 온카지노 slots, poker, and other

    RépondreSupprimer
  2. The King Casino | Situs Judi Slot Online Terbaik 2021
    Play online septcasino Pragmatic Play https://septcasino.com/review/merit-casino/ Slots at The 토토 사이트 도메인 King Casino - Member Baru & https://sol.edu.kg/ Terpercaya 2021! herzamanindir Rating: 98% · ‎240,388 votes

    RépondreSupprimer
  3. The King of Dealer
    I've been in casino all my life, and I like poker, but poker is the main thing in the game and there is never 카지노 a dull moment when I put a

    RépondreSupprimer
  4. Through June 30 of this year, $3.04 billion in sports activities betting income was totaled — a tempo that will shatter last year’s document. By 2025, based on Morgan Stanley, income might eclipse $7 billion. Other business projections land in an analogous ballpark, between $6 billion and $10 billion. Utah will be the least gambling-friendly state 파라오카지노 in the nation. The state’s deep connection with the Mormon faith — which prohibits playing, amongst other things — makes any move to legalize sports activities betting unlikely to take root.

    RépondreSupprimer

Enregistrer un commentaire