Perfecto. Gracias.
Saludos.

Fernando Pérez 

Cerámica Saloni. Dpto. Sistemas



Santillana, Gerardo escribió:
tengo este ejemplo a ver si te sirve
 
Saludos                                                         
                                                                    

Gerardo Santillana
IT Department
Delphi Mechatronic Systems
Phone USA  (956) 554 5832
Phone MX  01868 8128163   x.5832

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On Behalf Of Fernando Pérez
Sent: Tuesday, January 31, 2006 10:16 AM
To: Foro 400
Subject: Acceso JDBC nativo

Saludos, foreros.

¿Algún alma caritativa me podría dar un ejemplo básico de como utilizar jdbc nativo para un insert y un update, por ejemplo (por supuesto en una aplicación java en el ISeries), o al menos decirme donde puedo encontrar uno ?

Gracias anticipadas

--
Saludos.

Fernando Pérez 

Cerámica Saloni. Dpto. Sistemas

****************************************************************************************

Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you.

****************************************************************************************

////////////////////////////////////////////////////////////////////////////////// // // JDBCPopulate example. This program uses the AS/400 JDBC driver to // create and populate a table. // // Command syntax: // JDBCPopulate system collectionName tableName // // For example, // JDBCPopulate MySystem MyLibrary MyTable //

//////////////////////////////////////////////////////////////////////////////////

import java.lang.*;
import java.sql.*;
import java.util.*;
import com.ibm.db2.jdbc.app.*;

class JDBCPopulate
{



    // Strings to be added in the WORD column of the table.
    private static final String words[]
        = { "One",      "Two",      "Three",    "Four",     "Five",
            "Six",      "Seven",    "Eight",    "Nine",     "Ten",
            "Eleven",   "Twelve",   "Thirteen", "Fourteen", "Fifteen",
            "Sixteen",  "Seventeen","Eighteen", "Nineteen", "Twenty" };



    public static void main (String[] parameters)
    {
        // Check the input parameters.
        if (parameters.length != 3) {
            System.out.println("");
            System.out.println("Usage:");
            System.out.println("");
            System.out.println("   JDBCPopulate system collectionName tableName");
            System.out.println("");
            System.out.println("");
            System.out.println("For example:");
            System.out.println("");
            System.out.println("");
            System.out.println("   JDBCPopulate MySystem MyLibrary MyTable");
            System.out.println("");
            return;
        }

        String system           = parameters[0];
        String collectionName   = parameters[1];
        String tableName        = parameters[2];

        Connection connection   = null;

        try {

            // Load the AS/400 Toolbox for Java JDBC driver.
          //DriverManager.registerDriver(new com.ibm.db2.jdbc.app.DB2Driver ());
        //DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
        //  Class.forName("com.ibm.as400.access.AS400JDBCDriver");
            Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
            // Get a connection to the database.  Since we do not
            // provide a user id or password, a prompt will appear.
            //
            // Note that we provide a default schema here so
            // that we do not need to qualify the table name in
            // SQL statements.
            //
            connection = DriverManager.getConnection ("jdbc:db2://"
        //  connection = DriverManager.getConnection ("jdbc:as400://"
                + system + "/" + collectionName);

            // Drop the table if it already exists.
            try {
                Statement dropTable = connection.createStatement ();
                dropTable.executeUpdate ("DROP TABLE " + tableName);
            }
            catch (SQLException e) {
                // Ignore.
            }

            // Create the table.
            Statement createTable = connection.createStatement ();
            createTable.executeUpdate ("CREATE TABLE " + tableName
                + " (I INTEGER, WORD VARCHAR(20), SQUARE INTEGER, "
                + " SQUAREROOT DOUBLE)");

            // Prepare a statement for inserting rows.  Since we
            // execute this multiple times, it is best to use a
            // PreparedStatement and parameter markers.
            PreparedStatement insert = connection.prepareStatement ("INSERT INTO "
                + tableName + " (I, WORD, SQUARE, SQUAREROOT) "
                + " VALUES (?, ?, ?, ?)");

            // Populate the table.
            for (int i = 1; i <= words.length; ++i) {
                insert.setInt (1, i);
                insert.setString (2, words[i-1]);
                insert.setInt (3, i*i);
                insert.setDouble (4, Math.sqrt(i));
                insert.executeUpdate ();
            }

            // Output a completion message.
            System.out.println ("Table " + collectionName + "." + tableName
                + " has been populated.");
        }

        catch (Exception e) {
            System.out.println ();
            System.out.println ("ERROR: " + e.getMessage());
        }

        finally {

            // Clean up.
            try {
                if (connection != null)
                    connection.close ();
            }
            catch (SQLException e) {
                // Ignore.
            }
        }

        System.exit (0);
    }



}

  
begin:vcard
fn;quoted-printable:Fernando P=C3=A9rez
n;quoted-printable:P=C3=A9rez;Fernando
org:;Sistemas
email;internet:[EMAIL PROTECTED]
tel;work:Ext. 627
x-mozilla-html:TRUE
version:2.1
end:vcard

Responder a