salut,
jai fais un programme qui insere dans un table un nom qu on a entrer a partir de JTextField mais l erreur suivante s affiche :
[Microsoft][Pilote ODBC Microsoft Access] Erreur de syntaxe dans l'instruction INSERT INTO.
voici une parti de programme ou il y a le probleme.
merci d avvance
final JTextField testField1 = new JTextField (" ");
pannel.add(testField1);
JButton bouton=new JButton(("enter"));
pannel.add(bouton);
f.getContentPane().add(pannel);
f.setVisible(true);
final String text = testField1.getText();
bouton.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
f.setVisible(false);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (Exception E) {
System.err.println("Pas de pilote !");
}
try{
String URL="jdbc:odbc:bd";
Connection conn=DriverManager.getConnection(URL,"","");
Statement st= conn.createStatement();
st.executeUpdate("INSERT INTO lieu (nom_lieu,x_lieu,y_lieu) VALUES("+text+","+xpos+","+ypos+");" );
System.out.println(" ligne insérée");
//while(rs.next()){
// System.out.println("nom:"+rs.getString(2)+" x:"+rs.getInt(3)+" y:"+rs.getInt(4));
//}
//rs.close();
st.close();
conn.close();
}
catch(SQLException e1){
System.err.println(e1.getMessage());
}}
}
); }}
Partager