I am using XAMPP MySQL and I have created a table to which I have named users and within it created the following:
When I try to save the photo in java it presents me with an error of the SQL in relation to the syntax:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an
error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near '"usuarios"
(usuarioid, nombre, foto) VALUES (1, 'test', _binary'‰PNG
Errores de consulta: #1064 - You have an error in your SQL syntax; check
the manual that corresponds to your MariaDB server version for the right
syntax to use near 'BINARY NOT NULL' at line 1
try{
String sql="INSERT INTO \"usuarios\"(usuarioid, nombre, foto)
VALUES (?, ?, ?)";
PreparedStatement ps=con.getConexion().prepareStatement(sql);
ps.setInt(1,Integer.parseInt(txtcodigo.getText()));
ps.setString(2,txtnombre.getText());
ps.setBinaryStream(3,fis,longitudBytes);
ps.execute();
ps.close();
lblfoto.setIcon(null);
txtcodigo.setText("");
txtnombre.setText("");
JOptionPane.showMessageDialog(rootPane,"Guardado correctamente");
}catch(SQLException | NumberFormatException | HeadlessException x){
System.out.println(""+x);
JOptionPane.showMessageDialog(rootPane, "exception 2 "+x);
}
' at line 1
Here I have the following error that I get in the database when I try to apply the BINARY attributes in BLOB:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an
error in your SQL syntax; check the manual that corresponds to your
MariaDB server version for the right syntax to use near '"usuarios"
(usuarioid, nombre, foto) VALUES (1, 'test', _binary'‰PNG
Errores de consulta: #1064 - You have an error in your SQL syntax; check
the manual that corresponds to your MariaDB server version for the right
syntax to use near 'BINARY NOT NULL' at line 1
try{
String sql="INSERT INTO \"usuarios\"(usuarioid, nombre, foto)
VALUES (?, ?, ?)";
PreparedStatement ps=con.getConexion().prepareStatement(sql);
ps.setInt(1,Integer.parseInt(txtcodigo.getText()));
ps.setString(2,txtnombre.getText());
ps.setBinaryStream(3,fis,longitudBytes);
ps.execute();
ps.close();
lblfoto.setIcon(null);
txtcodigo.setText("");
txtnombre.setText("");
JOptionPane.showMessageDialog(rootPane,"Guardado correctamente");
}catch(SQLException | NumberFormatException | HeadlessException x){
System.out.println(""+x);
JOptionPane.showMessageDialog(rootPane, "exception 2 "+x);
}
' at line 1
This is the method I created in Java to save the image:
%pre%