Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Java-JDBC-Oracle

Re: Java-JDBC-Oracle

From: Marco <haandm_at_hotmail.com>
Date: Tue, 27 Nov 2001 15:36:55 GMT
Message-ID: <3c03ad55.13785853@news.wirehub.nl>


Hai Davis,

You really helped me with this one......I managed my applet to connect to my Oracle database using the Appletviewer.....NOT with IE5.5......can you help me with that one as well? Am I missing something here what makes my applet not work in IE?

Hope you can help me on this one as well!?!

Thanks anyway!

Best regards,

Marco

On 20 Nov 2001 11:07:56 -0800, davis_swan_at_compuserve.com (Davis Swan) wrote:

>"OP" <olehp_at_teleaudio.com.pl> wrote in message news:<9s9bdc$501$1_at_news2.ipartners.pl>...
>> Hi:)
>> I'd like to connect to Oracle database from Java-applet.
>> Can anybody help me?
>>
>> Thanks in advance,
>> Oleh
>
>The following is an abstract from my Web page at
>http://ourworld.compuseve.com/homepages/davis_swan/macjava.html
>
>Although some of the information on that page is Mac specific, the
>examples have all been compiled under Windows '95 as well.
>========================================================
>Connecting to an Oracle Database with JDBC
>
>First, you will need to download the JDBC "thin" drivers from the
>Oracle Technet site (the advantage fo the thin drivers is that they
>are not platform specific). Registration at the site is free but
>downloads are to be used for non-commercial, evaluation purposes only.
>
>Finding the driver is a bit tricky since Oracle does not refer to Mac
>OS explicitly anywhere. However, the page
>
>http://otn.oracle.com/software/tech/java/sqlj_jdbc/content.html
>
>refers to "Version 8.0.5.2 JDBC(Thin and OCI) for Solaris" which is
>what you want. Clicking on this link and agreeing that you
>meet the "ELIGIBILITY EXPORT RESTRICTIONS" will take you to a page
>listing numerous versions of the Oracle JDBC drivers. I chose to
>download the "JDBC-Thin, 100% Java ( 1.7MB)" driver.
>
>Note: I was not able to use Netscape to download this file. However,
>by using IE 5, holding the mouse button down over the link, and
>choosing "Save this Link to Disk" I was able to get the file
>classes111.zip onto my desktop. You will want to copy this file into
>the development area where you are storing your own class files.
>
>You will need to have a remote Oracle database up and running,
>complete with a Listener process, before you can build your test
>application. I installed Personal Oracle 8 on a Windows '95 machine.
>Apart from having to configure the Listener and enabling two-phase
>commits, the installation was very straightforward.
>
>The following example code will create a connection to a remote Oracle
>database and display the results of a query;
>
>/ *
> * This example Applet connects to an Oracle database via the Oracle
>thin
> * JDBC drivers and prints a value selected from the database.
> * Assuming that the Oracle database is running on a remote sever,
>this applet will only
> * work if you use File -> Open -> Page in Navigator in Netscape, or
>File -> Open File in
> * Internet Explorer. This applet can NOT be served up as an HTTP
>page because of security
> * contraints on served applets.
> */
>import java.sql.*;
>import java.text.*;
>import java.applet.Applet;
>import java.awt.*;
>import java.awt.Graphics;
>
>public class JDBCTestApplet extends Applet {
> TextArea msgArea = new TextArea(20,20);
>//
>// The methods init, start, stop, and destroy are all methods of the
>applet class
>//
> public void init() {
>//
>// Add the text area to the default container
>//
> setLayout(new GridLayout(1,1));
> add(msgArea);
> }
>
> public void start() {
> outputTextLine("Starting the Applet ...");
>//
>// Load the Oracle JDBC driver
>//
> try
> { DriverManager.registerDriver(new
>oracle.jdbc.driver.OracleDriver());
>//
>// Set connection information
>// REPLACE THE USER, PASSWORD, IP ADDRESS, AND INSTANCE WITH
>ONES
>// APPROPRIATE FOR YOUR ORACLE ENVIRONMENT
>//
> String user = new String("Scott");
> String password = new String("Tiger");
> String database = new String ("192.168.111.222:1521:ORCL"
>);
> String msg = new String("Connecting to " + database + "\n"
> + "The following line(s) will be the result
>of the query ... please wait\n"
> +
>"------------------------------------------------------------------------");
> outputTextLine(msg);
> Connection conn = DriverManager.getConnection
>("jdbc:oracle:thin:@"
> + database, user, password);
> Statement stmt = conn.createStatement ();
>//
>// Get a set of rows from the database
>// REPLACE THIS QUERY WITH ONE APPROPRIATE FOR YOUR DATABASE
>//
> ResultSet rset = stmt.executeQuery ("select ENAME from EMP
>");
> while (rset.next ())
> {
> outputTextLine(rset.getString (1));
> }
> conn.close();
> } catch (SQLException ex ) {
> outputTextLine(ex.getMessage());
> }
> }
> public void outputTextLine(String outputString) {
> msgArea.appendText(outputString + "\n");
> repaint();
> }
>}
>
>Compile this program using javac, remembering to add the file
>classes111.zip to your CLASSPATH. You will probably get a warning
>message which can be ignored. Open SimpleText and type in the
>following;
>
><title>JDBC Test Applet</title>
>You should a report below
><hr>
><applet code="JDBCTestApplet.class" ARCHIVE="classes111.zip" width=375
>height=50
>alt="If you see this message, your Browser can't run the applet">
><param name=text value="I really love Java">
>If you see this message, your Browser doesn't understand the APPLET
>tag.
></applet>
>
>Save this file with the name JDBCTestApplet.html in the same folder as
>the files JDBCTestApplet.class and classes111.zip. You should now be
>able to use File -> Open from either Netscape or IE to run this applet
>and see the results of your query.
>
>Congratulations ! You have now built and run a JDBC application
>accessing a remote Oracle database.
Received on Tue Nov 27 2001 - 09:36:55 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US