JDBC ODBC para Acceder a una Base de Datos MS-Access

 import java.sql.*;

 public class dbAccess{

    public static void main(String[] args)    {

        try        {

            Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”);

            String database =

              “jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=myDB.mdb;”;

            Connection conn = DriverManager.getConnection(database, “”, “”);

            Statement s = conn.createStatement();

                       // crear una tabla

            String tableName = “myTable” + String.valueOf((int)(Math.random() * 1000.0));

            String createTable = “CREATE TABLE ” + tableName +

                                 ” (id Integer, name Text(32))”;

            s.execute(createTable);

                       // ingresar valor en la tabla

            for(int i=0; i<25; i++)            {

              String addRow = “INSERT INTO ” + tableName + ” VALUES ( ” +

                     String.valueOf((int) (Math.random() * 32767)) + “, ‘Text Value ” +

                     String.valueOf(Math.random()) + “‘)”;

              s.execute(addRow);

            }

            String selTable = “SELECT * FROM ” + tableName;

            s.execute(selTable);

            ResultSet rs = s.getResultSet();

            while((rs!=null) && (rs.next()))            {

                System.out.println(rs.getString(1) + ” : ” + rs.getString(2));

            }

            // elimicar la tabla

            String dropTable = “DROP TABLE ” + tableName;

            s.execute(dropTable);

            // cerrar  y limpiar

            s.close();

            conn.close();

        }  catch(Exception ex)  {

            ex.printStackTrace();

        }

    }

}

Anuncios

7 thoughts on “JDBC ODBC para Acceder a una Base de Datos MS-Access

  1. Do you mind if I quote a couple of your posts as long as I provide credit and sources
    back to your webpage? My blog is in the very same
    niche as yours and my users would certainly benefit from some of the information you present here.

    Please let me know if this ok with you. Cheers!

  2. Hello there, I found your web site by the use of Google even as looking for a
    related subject, your website came up, it seems to be good.
    I have bookmarked it in my google bookmarks.

    Hi there, simply become alert to your weblog via Google, and found that it is truly informative.
    I am gonna watch out for brussels. I will be grateful if you continue this in future.
    Many other folks will likely be benefited from your writing.
    Cheers!

  3. Write more, thats all I have to say. Literally, it seems as though you relied on the video to
    make your point. You clearly know what youre talking about, why waste your intelligence on just posting videos to your site when you could be giving us something informative to read?

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s