0

Here is the issue I'm using Netbeans and MySQL latest version I'm using the BIT(1) Field type in MySQL to manage the Boolean types in my app

When storing Data in the data base if I use this code everything works well

PreparedStatement st = con.prepareStatement("INSERT INTO `postetransfo`.`utilisateur`"
                + " (`dbLogin`, `dbMDP`, `dbNom`, `dbPrenom`, `dbAjPoste`, `dbModPoste`, `dbMajPoste`, `dbAjMesure`,"
                + " `dbModMesure`, `dbDroitAdmin`, `dbTracerAdmin`) VALUES (?,?,?,?,b'0',b'0',b'0',b'0',b'0',b'0',?)");

        st.setString(1, login);
        st.setString(2, "changemoi");
        st.setString(3, nom);
        st.setString(4, prenom);
        //st.setString(5, "b'0'");
        //st.setString(5, "b'0'");
       // st.setString(6, "b'0'");
       // st.setString(7, "b'0'");
       // st.setString(8, "b'0'");
       // st.setString(9, "b'0'");
        st.setString(5, "TEST");

But when I want to make all the query Dynamic I get the following exception

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'dbAjPoste' at row 1
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4118)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
Inbar Rose
  • 41,843
  • 24
  • 85
  • 131
  • Seems like the data you're trying to put into the field `dbAjPoste` doesn't match the size of the actual data type in the schema. – NilsH May 08 '13 at 11:42
  • you could try st.setBoolean() - but I'm not sure it'll work – DaveH May 08 '13 at 11:43

2 Answers2

0

You should use setBoolean rather than setString for a BIT parameter.

Will A
  • 24,780
  • 5
  • 50
  • 61
0

Data truncation: Data too long for column 'dbAjPoste' at row 1 means you want to store the more value than size present in DB.

**

  • Example

**

1st coloum type Varchar2(5) but you want to insert string value like "abcdefghij". The length of string is 10 but in DB it can take upto 5 only.

Hope it's useful for you..

Janny
  • 681
  • 1
  • 8
  • 33