How to connect to a remote database with the JDBC-ODBC-bridge?
843854Feb 14 2004 — edited Feb 16 2004Hi,
have successfully tried to connect to a MS Access database via the JDBC-ODBC-bridge (see also the
attached sourcecode..). This database is on my local computer and I had generated a ODBC-datasource
before in my system's configurations....
Now my question(s):
How do I connect to a database which is on a remote computer?? How would I have to change the
sourcecode if this application shall be executed on a machine different from the machine running the
database?? I mean, somehow I have to connect to the remote computer, but how??
Secondly, I am right, that the ODBC-configurations only have to be performed on the machine running the
database and not on every machine running my application?? Otherwise it wouldn't make sense, because
every user would have to fatfinger in his/her system's configurations, right??
It would be nice if someone could help me with this (simple) question...Maybe you have a little
source code fragment???? Thank you.
here the sourcecode to connect to a local database with the JDBC-ODBC-bridge:
/*
Connects to a local database, for which a ODBC-datasource has been generated with the name
TESTDB1.....
*/
import java.io.*;
import java.sql.*;
public class Datenbanken111
{
public static Connection con;
public static DatabaseMetaData dbmeta;
public static void main(String [] args)
throws Exception
{
try
{
//load the Jdbc-odbc-bridge
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//generate the Connection-object
con = DriverManager.getConnection("jdbc:odbc:TESTDB1");
}
catch (Exception e)
{
System.out.println("Error!!!!!!");
System.exit(0);
}
con.close();
}
}