Last Updated
Viewed 37 Times

i want to insert inputs i take from user into mysql database the connection is right but the insertion gives me error

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 ''u_fname', 'u_lname', 'u_uname', 'u_pass', 'u_age', 'u_adderess') values('20','o' at line 1

My code is:

public void adduser(User s) {
   try {
        sql = "insert into users ('u_fname', 'u_lname', 'u_uname', 'u_pass', 'u_age', 'u_adderess')"
                + "values('" + s.getFirstname() + "','" + s.getLastname()
                + "','" + s.getUsername() + "','" + s.getPassword() + "','" + s.getAge() + "','" + s.getAdderss() + "')";
        stmt = conn.createStatement();
        int i = stmt.executeUpdate(sql);
        if (i > 0) {
            System.out.println("ROW INSERTED");
        } else {
            System.out.println("ROW NOT INSERTED");
    } catch (Exception e) {


My Question is: How can I inset a BigInteger variable as BIGINT in MySQL DB?? It seems to me that the preparedstatement object in Java does not have a method supports this type?

I want to insert arabic information to the database but always get caracters like this : ابو نص. I use the UTF-8 encoding in my pages and i set my database to utf8_general_ci.

I read many questions similar to this question but I don't find a solution for my case.

this is a solution but with php and i don't know how to do the same thing in java.

The code of insert (by JdbcTemplate)

final String move_insert = "insert into r_movement (PPR,cd_fonc,nom_etabl,ville,delegation,date_debut,date_fin,nbjour,nbmois,nbannees,cina,cinn) "
               + "values (?,?,?,?,?,?,?,?,?,?,?,?)";

       .update(move_insert, new Object[] {move.getPpr(),move.getFonction(),move.getNom_etabl(),move.getVille(),move.getDelegation(),move.getDate_debut(),move.getDate_fin(),c.getNbjours(),c.getNbmois(),c.getNbyears(),move.getCina(),move.getCinn()});

This is my table :

CREATE TABLE `r_movement` (
 `id_move` int(11) NOT NULL AUTO_INCREMENT,
 `PPR` int(11) NOT NULL,
 `cd_fonc` varchar(255) CHARACTER SET utf8 NOT NULL,
 `nom_etabl` varchar(255) CHARACTER SET utf8 NOT NULL,
 `ville` varchar(255) CHARACTER SET utf8 NOT NULL,
 `delegation` varchar(255) CHARACTER SET utf8 NOT NULL,
 `date_debut` date NOT NULL,
 `date_fin` date NOT NULL,
 `nbjour` int(255) NOT NULL,
 `nbmois` int(255) NOT NULL,
 `nbannees` int(255) NOT NULL,
 `CINA` varchar(255) CHARACTER SET utf8 NOT NULL,
 `CINN` varchar(255) CHARACTER SET utf8 NOT NULL,
 PRIMARY KEY (`id_move`)

I have poor knowledge about programming. I need to save image in MySQL database. I have created a database table and there is a column to add image with longblob data type. I have code to a button to choose image from folder in PC then it load to a jlable. Now I need to insert this image to a database.

This is my code;

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    JFileChooser fc=new JFileChooser(); 
    File f=fc.getSelectedFile(); 
    String path=f.getAbsolutePath(); 
    jLabel1.setIcon(new ImageIcon(path)); 

        FileInputStream fin=new FileInputStream(f); 
        int len=(int)f.length(); Class.forName("com.mysql.jdbc.Driver"); 

        Connection con=DriverManager.getConnection("jdbc:my­sql://localhost/hss", "root", "bis123"); 
        PreparedStatement ps=con.prepareStatement("Insert into profile values(?)"); 

        ps.setBinaryStream(1, fin, len); 
        int status=ps.executeUpdate(); 

        if(status > 0) { 
            jLabel2.setText("Successfully inserted in DB"); 
            jLabel2.setText("Image not inserted!"); 
    }catch(Exception e){

Similar Question 4 (1 solutions) : Tomcat/Java - Insert into a mysql database

Similar Question 5 (2 solutions) : java insert data into Mysql database