applets can only access databases on the server from which they were downloaded. Normally, the Java Security Manager will prohibit a TCP connection from being made to an unauthorized hostname; that is, if the TCP connection is being made from within the Java Virtual Machine (JVM). In the case of the Bridge, this connection would be made from within the ODBC driver, outside the control of the JVM. If the Bridge could determine the hostname that it will be connected to, a call to the Java Security Manager could easily check to ensure that a connection is allowed. Unfortunately, it is not always possible to determine the hostname for a given ODBC data source name. For this reason, the Bridge always assumes the worst. An untrusted applet is not allowed to access any ODBC data source. What this means is that if you can t convince the Internet browser in use that an applet is trusted, you can t use the Bridge from that applet. The ODBC URL To make a connection to a JDBC driver, you must supply a URL. The general structure of the JDBC URL is jdbc:: where subprotocol is the kind of database connectivity being requested, and subname provides additional information for the subprotocol. For the Bridge, the specific URL structure is: jdbc:odbc:[;attribute-name=attribute-value]… The Bridge can only provide services for URLs that have a subprotocol of odbc. If a different subprotocol is given, the Bridge will simply tell the JDBC DriverManager that it has no idea what the URL means, and that it can t support it. The subname specifies the ODBC data source name to use, followed by any additional connection string attributes. Here s a code snippet that you can use to connect to an ODBC data source named Accounting, with a user name of dept12 and a password of Julie: // Create a new instance of the JDBC-ODBC Bridge. new jdbc.odbc.JdbcOdbcDriver(); // The JDBC-ODBC Bridge will have registered itself with the JDBC // DriverManager. We can now let the DriverManager choose the right // driver to connect to the given URL. Connection con = DriverManager.getConnection(”jdbc:odbc:Accounting”, “dept12″, “Julie”); An alternative way of connecting to this same data source would be to pass the user name and password as connection string attributes: Connection con = DriverManager.getConnection(”jdbc:odbc:Accounting;UID= dept12;PWD=Julie”); A third, more robust way of connecting would be to use a java.util.Properties object. DriverManager.getConnection is overloaded to support three versions of the interface: public static synchronized Connection getConnection(String url, String user, String password) throws SQLException;
We offer quality web hosting with only $3.99 per month with unlimited email addresses, unlimited bandwidth, and unlimited server space. Check our web hosting unlimited bandwidth section.
This entry was posted
on Saturday, September 29th, 2007 at 9:58 pm and is filed under Java and JBoss Server Pages.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.