Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/01/2013, 04:03
pitregallego
 
Fecha de Ingreso: julio-2012
Mensajes: 13
Antigüedad: 11 años, 9 meses
Puntos: 0
INSER query no funciona

Hola a todos y gracias por adelantado,

Tengo que pasar mucha información de un fichero a una base de datos por lo que he hecho un pequeño programa en java que lee el fichero y ejecuta las queries necesarias para insertar la información.

Código:
 public static void main(String[] args) {
        
        // TODO code application logic here

        //Read txt file
        readFile();
        //Open DB
        activeConn = createConnection();
        //Execute Query
        int i = 0;
        try {
            for (i = 0; i < toolName.size(); i++) {
                if(!checkToolName(toolName.elementAt(i))){
                    insertTooldata(toolName.elementAt(i));
                    insertVersionData(toolName.elementAt(i), version.elementAt(i));
                    System.out.println("Insertado: " + toolName.elementAt(i) + " - " + version.elementAt(i) );
                }
            }
        } catch (SQLException ex) {
            System.out.println("Error al insertar " + toolName.elementAt(i) + version.elementAt(i));
            ex.printStackTrace();
        }
            
        
        
    }
Código:
private static void insertTooldata(String toolName)throws SQLException {

        String query = "INSERT INTO tbl_Tool"
                + "(Name, AutoLicenceTool, FK_Type, IntranetVisible,    FK_BusinessUnitID,FK_KatNr)"
                + "VALUES(?,?,?,?,?,?)";

        PreparedStatement psmt = activeConn.prepareStatement(query);
        psmt.setString(1, toolName);
        psmt.setBoolean(2, false);
        psmt.setString(3, "TSim Plugin");
        psmt.setBoolean(4, false);
        psmt.setInt(5, 3);
        psmt.setInt(6, 7);
        psmt.executeUpdate();
        
    }


 private static void insertVersionData(String toolName, String version) throws SQLException{
               
        String query = "INSERT INTO tbl_ToolVersion(FK_Tool, FK_EncProject, Version,"
    +"InsertDate, Release, ExpireDate, FK_Freigabe, FreigabeDokument, Developer,AutoLicenceVersion) "
                + "VALUES(?,?,?,?,?,?,?,?,?,?)";
        PreparedStatement psmt = activeConn.prepareStatement(query);
        psmt.setString(1, toolName);
        psmt.setString(2, toolName);
        psmt.setString(3, version);
        psmt.setDate(4, null);
        psmt.setBoolean(5, false);        
        psmt.setDate(6, null);
        psmt.setString(7, "Intern");
        psmt.setString(8, null);
        psmt.setString(9, null);
        psmt.setBoolean(10, false);
        psmt.executeUpdate();
        
        
        
        
    }
Cuando lo ejecuto funciona correctamente pero cuando busco esos datos en al base de datos no existen. Que es lo que falla¿? porque no se insertan los datos?

Saludos