Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Connecting to Oracle DB through Java Applet problem

Options
  • 09-03-2007 4:59pm
    #1
    Registered Users 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 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 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