0

首先,我想指出,当有 1 行信息时这有效,但由于某种原因有很多信息时无效...这就是我的问题...由于代码相当长,我将其分段发布:

   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);

    }

像这样移动到字符串并删除所有额外的部分:

    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);
        }

最后一部分抓住了

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

Donno 这里有什么问题

4

2 回答 2

0

鉴于错误,我怀疑您设置的字符串之一比列的声明长度长。在这种情况下,驱动程序必须抛出这样的异常。

因此,请检查字符串的长度并将它们与表中列的声明长度进行比较。

于 2012-07-10T15:08:04.070 回答
0

似乎结合绅士的回答并为元素创建一个新循环将产生所需的形式

于 2012-07-11T07:24:52.087 回答