Pregunta

I am Trying To Insert Finger Print Data From My Form to the DataBase but i Got the Following Exception,

com.microsoft.sqlserver.jdbc.SQLServerException: String or binary data would be truncated.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1515)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:404)
at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:350)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)

I know i have implemented the Serialization MeChanism in a Wrong Fashion , But i Don't Know How to do that ,

Here is the Code What i Did,

public void setPerson(){
     tfcNIC.setText(tfcnic1.getText()+tfcnic2.getText()+tfcnic3.getText());
     Person p = new Person();
     p.setName(tfname.getText());
     p.setFname(tfFname.getText());
     p.setAddr(tfaddr.getText());
     p.setCnic(tfcNIC.getText());
     p.setfPrint(((MainForm)getOwner()).getTemplate().serialize());   <--- My Stupid Serialization Step,

In Person Class

public void setfPrint(byte[] fp){
    fPrint = fp;          <----- Setter method for Finger Print Of Person
}

Inserting Data Into DataBase

public void setPersonStatement(String nm,String fn,String cn,String add, byte[] fpt) {
    String Sql = "INSERT INTO PERSON (NAME, FNAME, CNIC, ADDR, FPT) VALUES ( ?,?,?,?,?)";
    try {
        if(con==null){
            System.out.println("Connection error");
        }
        else {
            System.out.println("Connection ok");
        }


        pst2=con.prepareStatement(Sql);

    System.out.println(nm);
    pst2.setString(1, nm);
    pst2.setString(2, fn);
    pst2.setString(3, cn);
    pst2.setString(4, add);
    pst2.setBytes(5, fpt);

    pst2.executeUpdate();

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        System.out.println("SQL Error");
        e.printStackTrace();
    }
    }

the Data Type For Finger Print in DataBase is VarBinary, of size 1024, I am new at the Serialization Concept, so If Anyone can tell Me What to Do,

i am Using Digital Persona URU 4000 b and there One touch SDk For Java API

¿Fue útil?

Solución

As Amir Keibi Said, That was not the problem with the Serialization,The Actual Problem was with the Size of FPT Column in DataBase, I increased that From 1024 to 2000 and Everything Worked Fine. Now I Can Save Finger Prints In DataBase.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top