0

First off id like to note that this works when there is 1 row of information but not when there is many for some reason... which is what my question is about... As the code is decently long i will post it in pieces:

   int count = jTable1.getRowCount();

 for(int i=0;i<count;i++){
//uusi muodostus//


        SET0listm.add(i, txtTestiNIMI1.getText());
        System.out.println("SET0"+SET0listm);

...

    SAVED8listm.addElement(jTable1.getModel().getValueAt(i,7));
        System.out.println("SAVED8"+SAVED8listm);

    }

Move to string and remove extra parts for all like so:

    String SET0listmtostring = SET0listm.toString();
        SET0listmtostring = removeChar(SET0listmtostring, ']');
        SET0listmtostring = removeChar(SET0listmtostring, '[');

String sqla1 = "INSERT INTO MIT(MTY_KOD,MTY_TYY,MTY_ALU,MTY_PAR1,MTY_PAR2,MTY_TOL,MTY_KAN,MTY_DATE) "+"VALUES (?,?,?,?,?,?,?,?)";

 try{
   pst = conn.prepareStatement(sqla1);

   pst.setString(1, SET0listmtostring);
   pst.setString(2, SET2listmtostring);
   pst.setString(3, SET1listmtostring);
   pst.setString(4, SAVEDlistmtostring); 
   pst.setString(5, SAVED3listmmtostring); 
   pst.setString(6, SAVED5listmmtostring); 
   pst.setString(7, SET3listmtostring); 
   pst.setString(8, SET2listmtostring); 
   pst.executeUpdate();}
   catch (Exception e) {
   System.out.println("MITCLAUSE "+e);
        }

The last part catches

MITCLAUSE com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.

Donno what teh problem is here

NeedyHelpo
  • 13
  • 6

2 Answers2

0

Given the error, I suspect one of the strings you set is longer than the declared length of the column. In that case a driver has to throw an exception like this.

So, check the lengths of your strings and compare them to the declared lengths of the columns in the table.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • you were correct I checked and it actually iterates the code repeat too many times...so for example: SAVED8 = [24, 24, 24, 24] is what i want... and i get SAVED8 = [24] , [24,24], [24,24,24], [24, 24, 24, 24].. so need to change the code to only include max version. – NeedyHelpo Jul 10 '12 at 17:39
  • there is no error on the other size but putting the date in 4 times probably creates a proceedural error since im using varchar30 atm.. so wil lsee if that works – NeedyHelpo Jul 10 '12 at 17:49
  • This solved the problem of getting it to the database... suppose the problem now is getting from the 1 row it goes into to move into all i rows – NeedyHelpo Jul 10 '12 at 17:56
0

it seems to be that with a combination of the gentlemans answer and creating a new loop for the elements will produce the required form

NeedyHelpo
  • 13
  • 6