Problème d'excution de requete
sarah_insat
Messages postés
48
Date d'inscription
Statut
Membre
Dernière intervention
-
Utilisateur anonyme -
Utilisateur anonyme -
Bonjour,
J'ai reussi enfin à établir la connexion entre mysql et jbuilder (java) mais le problème maintenant concerne les requetes.
Aucune requête ne s'excecute et une liste d'exceptions apparait.
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Erreur de syntaxe près de 'table' à la ligne 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)
at pfe.Test.executeMyQuery(Test.java:32)
at pfe.testsql.main(testsql.java:9)
Exception in thread "main"
Je ne comprends pas se pose le problème
voici mon code
import java.sql.*;
import java.io.*;
import java.lang.String;
public class Test {
Connection myconn = null;
Statement stmt = null ;
ResultSet rs = null ;
public Test() {
super();
}
public void connectToDB() throws ClassNotFoundException,SQLException{
//chargement du pilote
Class.forName ("com.mysql.jdbc.Driver");
//création de la connexion
myconn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
}
public int executeMyUpdate(String sql) throws SQLException{
stmt=myconn.createStatement();
int nb = stmt.executeUpdate(sql);
return nb;
}
public ResultSet executeMyQuery(String sql) throws SQLException{
stmt=myconn.createStatement();
rs = stmt.executeQuery(sql);
return rs; }
}
--------------------------------------------------------------------------------------------------------------------
import java.sql.*;
import java.sql.ResultSet;
public class testsql {
public static void main (String args[]) throws SQLException,
ClassNotFoundException {Test t= new Test();
t.connectToDB();
ResultSet res = t.executeMyQuery("select nom from table");}
}
je travaille avec le easyphp 1.8.
Je vous en prie de me bien répondre
et merci.
J'ai reussi enfin à établir la connexion entre mysql et jbuilder (java) mais le problème maintenant concerne les requetes.
Aucune requête ne s'excecute et une liste d'exceptions apparait.
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Erreur de syntaxe près de 'table' à la ligne 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1026)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2536)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2465)
at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1383)
at pfe.Test.executeMyQuery(Test.java:32)
at pfe.testsql.main(testsql.java:9)
Exception in thread "main"
Je ne comprends pas se pose le problème
voici mon code
import java.sql.*;
import java.io.*;
import java.lang.String;
public class Test {
Connection myconn = null;
Statement stmt = null ;
ResultSet rs = null ;
public Test() {
super();
}
public void connectToDB() throws ClassNotFoundException,SQLException{
//chargement du pilote
Class.forName ("com.mysql.jdbc.Driver");
//création de la connexion
myconn=DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
}
public int executeMyUpdate(String sql) throws SQLException{
stmt=myconn.createStatement();
int nb = stmt.executeUpdate(sql);
return nb;
}
public ResultSet executeMyQuery(String sql) throws SQLException{
stmt=myconn.createStatement();
rs = stmt.executeQuery(sql);
return rs; }
}
--------------------------------------------------------------------------------------------------------------------
import java.sql.*;
import java.sql.ResultSet;
public class testsql {
public static void main (String args[]) throws SQLException,
ClassNotFoundException {Test t= new Test();
t.connectToDB();
ResultSet res = t.executeMyQuery("select nom from table");}
}
je travaille avec le easyphp 1.8.
Je vous en prie de me bien répondre
et merci.
A voir également:
- Avec un moteur de recherche généraliste, elle souhaite limiter les résultats de sa recherche aux pages de l’organisation internationale du travail. quelle requête doit-elle taper dans le champ de recherche ?
- Recherche automatique des chaînes ne fonctionne pas - Guide
- Google moteur de recherche page d'accueil - Guide
- Rechercher ou entrer l'adresse mm - recherche google - Guide
- Copiez la ligne qui indique aux moteurs de recherche de ne pas référencer la page. - Forum Réseaux sociaux
- Recherche photo - Guide
3 réponses
Bonjour,
votre message stipule qu'il y a une erreur de syntaxe à la ligne 1.
verifiez la voir s'il ne manque pas un . une ; .....
votre message stipule qu'il y a une erreur de syntaxe à la ligne 1.
verifiez la voir s'il ne manque pas un . une ; .....