Article View: es.comp.lenguajes.java
Article #29497Re: Sigo con los problemas de JDBC.
From: Martin Jul
Date: Thu, 18 Dec 1997 00:00
Date: Thu, 18 Dec 1997 00:00
68 lines
2236 bytes
2236 bytes
!Hola!
> Pero no hay manera de conectarse a la jo...a tabla. :-(
>
Esto codigo es de uno de mi applets. Se conecta a un base da data
utilizando el JDBC-ODBC-bridge y hace un consulta. El base tiene que
ser registrado con el ODBC subsystem de tu maquina. En Windoze se
utiliza el "32 bit ODBC Administrator" para esto.
//...
Driver driver;
String drivername = "sun.jdbc.odbc.JdbcOdbcDriver";
Connection connection;
Statement statement;
ResultSet resultset;
ResultSetMetaData resultsetmetadata;
// ...
//* Conectar al base de datos:
try {
// load and instantiate the JDBC driver
driver = (Driver)Class.forName( drivername ).newInstance();
if( driver.jdbcCompliant() &&
driver.acceptsURL( databaseURL ) ) {
// Try to connect to the database
connection =
DriverManager.getConnection( databaseURL,
databaseUserName,
DatabasePassword );
statement = connection.createStatement();
} else {
if( driver.jdbcCompliant() )
throw new Exception( "JDBC-driver did not accept the DB URL" );
else
throw new Exception( "Driver is not JDBC-compliant." );
}
}
catch (Exception e) {
e.printStackTrace();
if( statusBar != null ) {
statusBar.setText( "ERROR! " + e.getMessage() );
}
}
}
//* Hace un consulta.
statusBar.setText( "Executing query..." );
resultset = statement.executeQuery( "SELECT * FROM employee;" );
resultsetmetadata = resultset.getMetaData();
--
Martin Jul (mjul@math.ku.dk) Tel. +45 31 18 42 70
--------------- "Who is John Galt?" ----------------
Technical Details
Message-ID:
<34985C37.C45D3E25@math.ku.dk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<01bd097f$622a0720$728775a3@mr-virus32>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1116f3,621760188b0c7c19 X-Google-Attributes: gid1116f3,public From: Martin Jul <mjul@math.ku.dk> Subject: Re: Sigo con los problemas de JDBC. Date: 1997/12/18 Message-ID: <34985C37.C45D3E25@math.ku.dk> X-Deja-AN: 299222228 Content-Transfer-Encoding: 7bit References: <01bd097f$622a0720$728775a3@mr-virus32> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: Get2Net Newsgroups: es.comp.lenguajes.java