Probleme ajout a une base de donnee

Résolu
xdev10 Messages postés 8 Date d'inscription   Statut Membre Dernière intervention   -  
xdev10 Messages postés 8 Date d'inscription   Statut Membre Dernière intervention   -
Bonsoir , apres execution de ce code il y a eu un declenchement d'une execption
package rrr;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

public class AjoutTable {



public static void main(String[] args) {
try{
Class.forName("org.postgresql.Driver");
System.out.println("Driver O.K.");

String url = "jdbc:postgresql://localhost/ClubVideo";
String user = "postgres";
String passwd = "projet";

Connection conn = DriverManager.getConnection(url, user, passwd);
System.out.println("Connexion effective !");
PreparedStatement state = conn.prepareStatement("INSERT INTO realisateur (id realisateur,nom,prenom) VALUES(12,'SALMON', 'Dylan')");

state.executeUpdate("INSERT INTO realisateur (id realisateur,nom,prenom) VALUES(12,'SALMON', 'Dylan')");
//afficheTable p = new afficheTable();
conn.close();
}
catch(Exception e)
{
System.out.println("erreur insertion");
}

}

}

3 réponses

KX Messages postés 16761 Date d'inscription   Statut Modérateur Dernière intervention   3 020
 
Bonjour,

Pour savoir quelle exception est levée il faudrait l'afficher.

catch (Exception e) {
    e.printStackTrace();
}
0
xdev10 Messages postés 8 Date d'inscription   Statut Membre Dernière intervention  
 
merci de votre reponse
il m'a affiche cette exception

ERREUR: erreur de syntaxe sur ou près de « realisateur »
Position : 28
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2182)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1911)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:173)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:645)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:481)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:409)
at rrr.AjoutTable.main(AjoutTable.java:26)
0
KX Messages postés 16761 Date d'inscription   Statut Modérateur Dernière intervention   3 020
 
Tu as un problème dans ta requête :

                           ↓
INSERT INTO realisateur (id realisateur,nom,prenom)
VALUES(12,'SALMON', 'Dylan')
0
xdev10 Messages postés 8 Date d'inscription   Statut Membre Dernière intervention  
 
c'est bon j'ai trouve la solution , j'ai met un espace entre deux mots de meme attribut dans ma base
0
xdev10 Messages postés 8 Date d'inscription   Statut Membre Dernière intervention  
 
merci pour votre reponse
0