Results 1 to 2 of 2
  1. #1
    Lagarto is offline Member
    Join Date
    Jul 2007
    Posts
    2
    Rep Power
    0

    Default Passing the Values

    Hello all :)

    I'm trying to do an INSERT using Netbeans as my IDE, and SQL server 2005 Express as my DB engine.

    When i compile my code its error free, but when i execute it wont do what its supposed to do.. Its not doing the insert.. i don't know exactly how to pass the values. Here's the code:

    Thanks!

    Java Code:
    private void IngresarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        Connection conexion;
        Statement sentencia;
        
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
         catch (Exception e){
        System.out.println("No se pudo conectar con el JDBC-ODBC");      
         return;
        }  
        
        try{
            conexion = DriverManager.getConnection("jdbc:odbc:con_sql","",""  );
            sentencia = conexion.createStatement();
            PreparedStatement insertar = conexion.prepareStatement("EXECUTE dbo.insertar " );
            
           
            
             
         
             
             String Nom = ("Nombre");
             String Ape = ("Apellido");
             String Ced = ("Cedula");
             String FechaN = ("Fecha_Nacimiento");
             String Sueldo = ("Sueldo");
             String TPrimario = ("Telefono_Primario");
             String TSecundario = ("Telefono_Secundario");
             String Movil = ("Movil");
             String Direccion = ("Direccion");
             
             
             
             
             
             
             
            
        }   
    catch( Exception e ) {
             System.out.println( e );
             return;
             }
        }

  2. #2
    boy22 is offline Member
    Join Date
    Jul 2007
    Posts
    36
    Rep Power
    0

    Default

    check this code:
    Java Code:
    private void IngresarActionPerformed(java.awt.event.ActionEvent evt) {                                         
        Connection conexion;
        Statement sentencia;
        
        try{
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
         catch (Exception e){
        System.out.println("No se pudo conectar con el JDBC-ODBC");      
         return;
        }  
        
        try{
    PreparedStatement insertar= con.prepareStatement("insert into table values( ? , ?,?,?,?,?,?)");
    insertar.setString(1,"Marito");
    insertar.setString(2,"Rojas");
    insertar.setInt(3,45123145);
    insertar.setDate(4,2007/5/2);
    insertar.setDouble(5,1800.2);
    insertar.executeUpdate();
        }   
    catch( Exception e ) {
             System.out.println( e );
             return;
             }
        }

Similar Threads

  1. Passing a value..
    By Lagarto in forum New To Java
    Replies: 3
    Last Post: 01-23-2011, 05:58 PM
  2. passing values from main page to pop up window
    By vicky in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 12-29-2008, 03:06 PM
  3. Replies: 4
    Last Post: 04-15-2008, 01:04 PM
  4. passing dynamically generated values
    By abhiN in forum Advanced Java
    Replies: 1
    Last Post: 01-20-2008, 03:21 AM
  5. passing an array into an instance
    By lockmac in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 09:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •