Bonjour,
J'ai un petit soucis au niveau d'une requête SQL Update.
J'ai tout une partie de code parfaitement fonctionnelle en l'état :
Je reçois bien la liste interminable de mes résultats dans la console, mais le but étant de mettre ma BDD à jour avec les résultats, j'ai ajouté ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 public void startIteration(String path, String year, String firstName, String secteur) { [...] System.out.println(fileName + secteur + " - " + mois[k] + " - " + indicateurs[j] + " : " + cellResult[i]); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 public void startIteration(String path, String year, String firstName, String secteur) { [...] database.updateContingent(indicateurs[j], cellResult[i], getCurrentYear(), mois[k], secteur); // Ligne 88 dans le StackTrace System.out.println(fileName + secteur + " - " + mois[k] + " - " + indicateurs[j] + " : " + cellResult[i]); }A partir de là, le programme me print toujours bien les résultats, mais entre chacun d'entre eux j'ai ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public void updateContingent(String indicateur, double valeur, int year, String mois, String secteur) { Connection conn = connect(); try { Statement state = conn.createStatement(); String sql = "UPDATE contingent " + "SET valeur = '" + valeur + "' " + "INNER JOIN secteurs " + "ON contingent.numero_secteur = secteurs.id " + "WHERE indicateur = '" + indicateur + "' AND annee = '" + year + "' " + "AND secteur_name = '" + secteur + "' AND mois = '" + mois + "'"; state.executeUpdate(sql); // Ligne 172 dans le StackTrace } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { System.out.println(e + " - Erreur lors de l'écriture dans la BDD"); } }
Après m'être renseigné, et bien que certaines infos se contredisent, j'ai cru comprendre que la requête sql UPDATE n'autorise pas de JOIN dans Java. Le problème c'est que dans ma requête, l'une de mes conditions pour mettre à jour les bonnes données est le "secteur_name" qui n'est pas directement accessible dans la table que je dois mettre à jour, mais via la table portant le nom "secteurs", secteurs qui sont donc liés par un id.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 org.postgresql.util.PSQLException: ERREUR: erreur de syntaxe sur ou près de « INNER » Position*: 40 at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2476) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2189) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:300) at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428) at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:301) at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:287) at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:264) at org.postgresql.jdbc.PgStatement.executeUpdate(PgStatement.java:244) at AVJ.Database.updateContingent(Database.java:172) at AVJ.IteratorExcel.startIteration(IteratorExcel.java:88) at AVJ.ControllerContingent.lambda$onUpdateButtonClick$1(ControllerContingent.java:175) at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) at javafx.event.Event.fireEvent(Event.java:198) at javafx.scene.Scene$MouseHandler.process(Scene.java:3757) at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485) at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381) at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$354(GlassViewEventHandler.java:417) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416) at com.sun.glass.ui.View.handleMouseEvent(View.java:555) at com.sun.glass.ui.View.notifyMouse(View.java:937) at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191) at java.lang.Thread.run(Thread.java:745)
Tout cela étant que je n'arrive pas à trouver un moyen d'imposer toutes mes conditions sans passer par un INNER JOIN, et je me demandais si quelqu'un de passage sur mon post aurait une idée, ou une habitude à me proposer pour contourner ce problème.
J'espère ne pas m'être trompé de catégorie en postant, comme c'est un problème SQL, mais spécifique au langage de Oracle à priori, j'ai pensé que c'était le meilleur endroit.
Un tout grand merci d'avance !
Partager