Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Connecting to Oracle DB through Java Applet problem

  • 09-03-2007 04:59PM
    #1
    Registered Users, Registered Users 2 Posts: 750 ✭✭✭


    When Using a java program that takes the information from the console, ie. Create table, I can get it to connect and update the database just fine. But when I try this from within a java applet, It doesn't seem to work. It compiles alright but doesn't update the database.

    Here is a sample code:
    import java.io.*;
    import oracle.jdbc.*;
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
     
    
    
    public class HelloWorld1 extends Applet 
    {
    
    
    	public HelloWorld1()
    				{
    		init();
    	
    	}
    		private Connection con = null;
    		  public void init()  {
    			 try {
                 DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    			String username = "****", password = "****";
    			con = DriverManager.getConnection("jdbc:oracle:thin:@oracle.***.****.****.ie:1521:oracle",username,password);
    			  } catch (SQLException ex)     {
                 System.out.println("Connection Error =  "  + ex.toString());
               }
    			 try {
    		     Statement stmt = con.createStatement();
    		     stmt.executeQuery("CREATE TABLE Stuff(bar VARCHAR2(40), beer VARCHAR2(40), price REAL)" );
    		     stmt.close();
    		  
    			 }
    			catch (SQLException ex) 
             {
               System.out.println("Error While Fetching Values =  "  +  ex.toString());
             }
    
    		 if(con != null)
    		{
    			try
    			{
    				con.close();
    			}
    			catch(Exception e)
    			{
    				System.out.println("Could'nt close connection \n"+e);
    			}
    		}
    
    		  }
    }
    

    My login details work grand from within a normal Java Program.
    Any help would be much appreciated.


Comments

  • Registered Users, Registered Users 2 Posts: 4,188 ✭✭✭pH


    Bound to be either:
    a classpath problem in the applet possibly not including the oracle-jdbc jar
    or
    Security/sandbox issues associated with Applets - they can only connect back to the machine that served the applet.

    what exceptions are you getting?


  • Closed Accounts Posts: 884 ✭✭✭NutJob


    pH wrote:

    Security/sandbox issues associated with Applets - they can only connect back to the machine that served the applet.

    Most likely cause oracle has to be running at the same address as the applet was loaded from a normal java app is not restricted in this way.


  • Registered Users, Registered Users 2 Posts: 750 ✭✭✭Bungalow Bill


    Okay I'm not too familiar with the security issues with Applets. I'm working from university machines in which the classpaths cannot be changed.

    I'm not really getting any error messages as the applet compiles and loads in firefox okay, but it just doesn't affect the database at all.


Advertisement
Advertisement