Applet and jdbc problem

hi all
I have problem when I connect the applet to mysql
and code inside init() is
try{
String userName = "root";
String password = "";
String url = "jdbc:mysql://localhost/test";
Class.forName ("com.mysql.jdbc.Driver").newInstance ();
conn = DriverManager.getConnection (url, userName, password);
          }catch(Exception e){
and I get a SQLException when
I run appletviewer
I am not sure what is the problem ....... driver .....or permission
because all ok when it is convert to un applet program
hope someone help

I'm getting a similar problem with almost exactly the same code. With appletviewer, I get
java.sql.SQLException: Unable to connect to any hosts due to exception: java.net.ConnectException: Connection refused
and loading the webpage from a browser I get
java.sql.SQLException: Unable to connect to any hosts due to exception: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:3306 connect,resolve)
Lots of the information I've looked up says to sign the applet; how does this work?
Brian.

Similar Messages

  • Applets and JDBC

    I am having a problem with applets and an SQL server. Let me explain my situation:
    - I have an SQL Server on a machine in my network
    - My Applet is being developped on my machine
    - When connecting to the server through a browser using the machine name (ie: http://myserver/applet.html), it works perfectly. However, when attempting to access it using the IP, it doesn't work.
    The server is behind a router, so I am not sure if that is blocking the connection from the outside or not, and I know the security restrictions of applets which state that I can't access a machine other than the one it is downloaded from - but I am not sure how this works with routers and forwarding.
    I've read about signing an applet, but the conditions that are usually listed don't seem to apply to me in this case.
    If anyone could help, it would be appreciated.
    - Don

    I should also state that I'm using Microsoft's JDBC driver and have tried switching the connection string from the server name to the IP address (internet and network IPs), with no luck.
    Thanks in advance,
    - Don

  • Applet and JDBC

    Ok, I have read that there is no way to attach to a remote database via a applet where they are not running on the same box. I have to ask this question so be patient with me.
    I have an applet that accesses a SQL Server2000 database using Microsoft�s type 4 database driver. It runs fine locally but when I try to access it from another machine it fails. It is running on an isolated secure Intranet. Is there not way to allow an applet to access a remote database with out using RMI, servlets, or CORBA? I under stand the problem with posting such an applet on the open internet.
    Thanks for your help
    Geof

    Internet, intranet, it's all the same as far as the applet rules are concerned.
    And wherever you read that applets can't connect to a remote database on a different server from the one where the applet was loaded from, that was wrong. You can do that if you sign the applet, which is the answer to your question.

  • Applets and JDBC-ODBC Bridge

    I have the following error when i try to run my program(I have used JFrame instead of JApplet ) :
    [Microsoft] [ODBC Driver Manager] Invalid cursor state
    I'm using VJ# and i read on oreilly's site that JDBC-ODBC bridge doesn't work with it, so how should i resolve the problem?
    could somebody suggest a better and easy-to-use Type 1 driver(which is free)

    Closing the statements defeats the purpose of prepared statements with my design. The whole point is to load them at startup and reuse them.
    Another driver is an option however where does one get one and are they free?
    I have implemented a temporary solution that I found in the archives. I have used a while statement to make sure that I have got to the end of the result set, however a nested if only looks for the first result. I am only retrieving one row from the database so only need the first. Logic says to me that rs.next() must have to evaluate to false. It is a bit messy but it works . . . so far.
    L

  • Net Beans and JDBC Problem

    Hi everybody, I am able to compile and run a program that uses the JDBC withing the Netbeans environment.(I developed the application within that ide). However after building the project, if i try to run it from the command prompt or from windows it does not work . If i run it from the command prompt, I get this error message below. What do I need to do to be able to run the program outside the environment.
    C:\>java -jar "D:\FinalProject\FinalProject\dist\FinalProject.jar"
    Exception in thread "main" java.lang.NoClassDefFoundError: com/mysql/jdbc/Driver
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at utilitly.DBConnectAndUtilities.<init>(DBConnectAndUtilities.java:50)
    at gui.mpisGui.<init>(mpisGui.java:23)
    at finalproject.Main.createAndShowGui(Main.java:24)
    at finalproject.Main.main(Main.java:35)
    below is the code i use for the database linking and interaction.
    import java.awt.Component;
    import java.awt.event.ActionListener;
    import java.sql.*;
    import java.text.DateFormat;
    import java.text.NumberFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JFrame;
    import javax.swing.Timer;
    import java.util.Vector;
    import javax.swing.JComboBox;
    import javax.swing.JFormattedTextField;
    import javax.swing.JPanel;
    import javax.swing.JRadioButton;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.JTextPane;
    import javax.swing.text.MaskFormatter;
    * @author Morrizle
    public class DBConnectAndUtilities{
    /**declare a connection that would be used*/
    private Connection dbcon;
    private Statement dbstmt;
    private ResultSet dbset;
    private String dbName = "mpisdb";
    private String patient_pers_info = "patient_pers_info";
    * Creates a new instance of DBConnectAndUtilities
    public DBConnectAndUtilities() {
    //this.dbName = dbName;
    /*load the driver and make a active connection/
    try{
    /*load driver*/
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    /*get an active connection*/
    dbcon = DriverManager.getConnection("jdbc:mysql://localhost/" + dbName , "root","morrfo");
    /*create a statement with which we can execute the update of database*/
         dbstmt = dbcon.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    /*prints the following if the connection is succesfully made with the database*/
    //System.out.println("Connection made");
    catch(Exception m){
    /*prints the trace of errors if the connection or loading of driver doesn't work*/
    m.printStackTrace();
    /*methods to update the database and tables
    returns true when the update is successful **/
    public boolean updateDB(String tableNValues){
         /*execute*/
    boolean result = false;
         try{
         dbstmt.executeUpdate(tableNValues);
    result = true;
         }catch(SQLException k){
              k.printStackTrace();
    return result;
    /*method to execute queries*/
    public ResultSet queryDB(String query){
              ResultSet m = null;
         try{
              m = dbstmt.executeQuery(query);
         }catch(SQLException q){
              q.printStackTrace();
         return m;
    /*method to close the connection*/
    public void closeConnection(){
    try {
    dbcon.close();
    } catch (SQLException ex) {
    ex.printStackTrace();
    public void closeStatement(){
    try {
    dbstmt.close();
    } catch (SQLException ex) {
    ex.printStackTrace();
    /*a utility method to return a varchar object as a string*/
    /* method to convert a string to varchar*/
    public String toVarchar(String convert){
    String converter = "";
    if(convert.isEmpty()){
    converter = null;
    }else{
    converter = "'"+ convert +"'";
    return converter;
    Please come to my aid . Please.!!!!!!!!!!!!!!!!! i need urgent help

    Please reference the following thread.
    http://forum.java.sun.com/thread.jspa?threadID=5177116&tstart=0

  • Applets and application problem plz help me

    Sir
    i design some buttons in cofeecup applet button factory
    it gives me an applet code.i design all drop down menus
    now i want to and it in my application
    by using a JSplitpane How can i add them in my application
    thanks in advance

    Creating a GUI with Swing
    http://java.sun.com/docs/books/tutorial/uiswing/

  • Special characters and JDBC problem

    I am trying to retrieve special characters, e.g. c from the
    database. The problem is that the characters always show
    up as ?. I use getString to get the data from the database.
    The character set that my database uses is US7ASCII and the
    sqlplus program displays the correct dataset. It's only
    in the Java program where the display gets all screwed up.
    Help or direction of any kind would be greatly appreciated.
    -- Balendu

    This is because you are using the wrong database character set
    for storing your data . In the 7-bit ASCII encoding scheme, c or
    other non 7-bit data do not exist.
    Java can not handle the conversion of invalid characters inside
    your database , because it does not know what they are. What you
    need to do is to change your database character set to match the
    encoding of the data inside your database.
    Please check out the Character set migration paper on the
    Globalization Support Home page.

  • Applets and package problem?

    i've got an applet that is declared part of a package:
    package myproj.mycollection.mypackage;
    in my applet tag i set the code:
    code=myproj.mycollection.mypackage.TestApplet.class
    early in TestApplet's init method i create an instance
    of another class which is also in that package:
    Otherclass oc = new Otherclass();
    when i use the jdk appletviewer for my html file file things work
    just fine, but when i use my browser to open the html file i get
    "Can not find class myproj/mycollection/mypackage/Otherclass"
    is this some applet security violation or have i mucked something
    up somewhere?

    You need to tell the browser that you're using a jar
    file
    <applet
    archive="jarfile.jar"
    </applet>
    This way, the JVM will look for the classes inside the
    jar file.except that i'm not using a jar file - the classes
    are all there (in the correct directory structure)
    with the html file.
    pat

  • I have a basic applet method timing problem with Firefox (and Chrome), not IE nor Opera. Works if JavaScript issues windows.alert() prior, fails otherwise.

    I have an applet method, which is invoked from a JavaScript function, that is triggered by the window.onload event. The problem seems to center in the loading of the applet and its methods.
    If I step through the 3 applet acceptance prompts (I chose to use a down-level Java), the applet method is never invoked, nor is an exception raised. How this happens is beyond my understanding.
    As additional information, the Init(), start(), and "desired" Java methods all use the synchronized keyword. This is an attempt to minimize the exposure to a multi-thread environment.
    If I issue a message from JavaScript (via window.alert()) PRIOR to invoking the method, I can get the desired results in special circumstances:
    1) When the alert is presented, Firefox also prompts, SIMULTANEOUSLY, to block/continue the applet (the first of the 3 applet acceptance prompts). I can accept that these are separate threads.
    2a) If I walk through the 3 applet acceptance prompts FIRST, and then hit the OK button on the alert message SECOND, I get the desired results, my applet method executes, and all is well (other than the fact that I would prefer not to have the alert in place at all).
    2b) If I hit the OK button on the alert message FIRST, and then walk through the 3 applet acceptance prompts SECOND, I get the same results as when the page loads WITHOUT the alert, which is the applet method is never invoked, nor is an exception raised. Weird, huh?
    The above problem only occurs when the browser and the applet's URL are loaded for the first time.
    Subsequent invocations (after the page & applet has been loaded initially) do not have the failing symptoms.
    It is my understanding that IE and Firefox (and Chrome and Opera, for that matter) each use the same implementation of JavaScript provided by Microsoft. Please correct me if this information is inaccurate.
    The failing page and it's applet are proprietary; I cannot provide the Internet URL, nor the Java or JavaScript source, to aid in your analysis.

    I can speak to the source code, but have no access to it.
    The current process/thread that invokes an applet method must check to see that the applet is not currently being loaded by another process/thread. If it is being loaded, the current process/thread should block until the load is complete, THEN attempt to invoke the applet method.
    Please forward my concern to a knowledgable developer. The nature of the problem, once identified, can be addressed in a very straightforward manner.

  • IIS, Javascript, Signed Applet and ASP Blank Page Problem

    Hi,
    I'm having a problem using a Signed Applet in a site that runs in a IIS (Windows Server 2003).
    My aspx web page uses the applet to read my smart card and get information from it.
    This applet uses an auxiliar dll (stored in a second Signed Jar file) in order to read the information from my smart card.
    The way the solution is design:
    1) Aspx page is asked from server
    2) Internet Explorer recieve the page and asks the server for it content (images, applet, javascripts, etc)
    3) After this the JVM runs (console opens)
    4) After the Aspx page render fully a javascript register onload fires and call an applet method
    5) Applet receive the call and run the logic of the method:
         - reads the smart card;
         - calls Javascript function in order to fill aspx fields with information from smart card
         - calls Javascript function the simulates a click in a botton of aspx page (in order to call server side part sending data readed from smart card to server)
    5) The server makes some logic with the information receive and responds to client registering in aspx page a call to another Javascrit function
    6) The client received the asnwer from server and runs the Javascript function registered on step 5)
         This Javascript calls another method from applet and runs the following logic:
         - reads more information from smart card;
         - call javascript function in order to fill more fields of aspx page with the information readed
         - calls Javascript function the simulates a click in a botton of aspx page (in order to call server side part sending data readed from smart card to server)
    7) The server makes some logic and call another pages with no Applets
    8) Client asks for a second page with the same applet and we start with another logic express on steps 1);2);3),4);5) and then 7).
    This is all ok, until sometimes the server stop responding correcly for requests regarding this two pages with the Applet.
    When this happens the server just responds with a blank page.
         - with fiddler I can seer the request for the aspx page (that uses the applet)
         - but server responds with a blank html page
    The JVM doesn't fire.
    The IIS log don't show errors.
    The eventviewer doesn't show errors.
    The problem is solved with an IIS reset or a Application Pool reset.
    After a while the problem returns.
    This problem occours for other user in another machine, the server just stops responding correcly to request regarding pages with applets, the other pages still continue to work.
    If we disable Java Control Panel->Advanced->Java Plug-in->Enable the next-generation Java Plug-in the problem seend to stop, but we can't force all clients to disable this option right?
    Or there is a way to force the Applet to run with this option disabled?
    As anyone experience similar problem?
    Regards,
    OF

    This is all ok, until sometimes the server stop responding correcly for requests regarding this two pages with the Applet.
    When this happens the server just responds with a blank page.
    - with fiddler I can seer the request for the aspx page (that uses the applet)
    - but server responds with a blank html pageWell, if http requests look identical in case of success and failure (pay attention to cookies, etc) then it has to be something on the server side.
    It could be that server gets into this wrong state because of previous requests made by applet but it is hard to tell.
    I am not clear how old/new plugin can make a difference unless your applets run in the legacy mode (i.e. you are actually trying to reuse SAME instance of the applet when
    it is loaded next time).
    I'd start with
    1) carefully comparing good/bad sessions
    2) checking whether server will serve correct response to another client when it serves "bad" page for current client
    3) add debug statements to aspx - it is scripted page, may be some condition is not met and then it returns blank?
    4) record all http requests in one session until you get to "error" state and then use any http server testing tool to "replay" this set of requests.
    You should be able to get server into the same state without use of applet. Then you can try to tweak set of requests to see what makes a difference.

  • Problem between SOAP Sender and JDBC Receiver

    Hi,
    I have a asynchronous scenary between SOAP Sender and JDBC Receiver.
    The idea is sending an ID for updating one register.
    Table structure is:
    TABLE AS_PERSONA
        (P_RUT                         VARCHAR2(10) NOT NULL,
        P_NOMBRE                       VARCHAR2(50),
        P_APELLIDO                     VARCHAR2(50))
    The ID is the P_RUT field.
    The structure of message that I send by SOAP, is the following:
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <SOAP-ENV:Body>
              <m:MT_CONS_SOAP xmlns:m="urn:prueba:voliva">
                   <CONSULTA>
                        <P_RUT>15445</P_RUT>
                   </CONSULTA>
              </m:MT_CONS_SOAP>
         </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    The JDBC receiver structure is:
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_CONS_PERSONA xmlns:ns0="urn:prueba:voliva">
         <Statement>
              <AS_PERSONA action="UPDATE">
                   <table>AS_PERSONA</table>
                   <access>
                        <P_NOMBRE>DELETE_BY_XI</P_NOMBRE>
                        <P_APELLIDO>DELETE_BY_XI</P_APELLIDO>
                   </access>
                   <key>
                        <P_RUT>15445</P_RUT>
                   </key>
              </AS_PERSONA>
         </Statement>
    </ns0:MT_CONS_PERSONA>
    When I do a call to SOAP by XMLspy, it returns a message without data, that means succesfull reply.
    I see message monitor and see the succesfull flag. But in the database it doesn't update the register.
    This scenario was proved using the File Sender and same JDBC Receiver, then result was succesfull.
    I proved SOAP Sender with a File Receiver, storing information from SOAP sender in an archive, and works well.
    Then I imagine that exist some problem between SOAP and JDBC. what could be happening ?
    Thanks.

    Hi,
    Looks like the problem is with the JDBC receiver...try updating the value in the table by using a File-JDBC scenario..does it work..check the adapter monitor in RWB..
    Regards,
    Sushumna

  • Sqlj and jdbc in a single program causing problems

    I am using both sqlj and jdbc in a single program(servlets) but after insatiaitng this program my other sqlj programs are not working while the JDBC pgms are working . Why is it so? How can I remedy it?

    Unfortunately, this description is still rather unspecific.
    It sounds, as if there might be an issue with the way database connections are established for the SQLJ and JDBC parts of your program. Could you provide more information on that, specifically on how you obtain JDBC connections and SQLJ connection contexts.

  • Applets and DataBase Access

    Hello, I want to know if it's posible data base acces from a Applet and how do it. The SQLException: No suitable Error is always in the output.The Applet code is:
    import java.applet.*;
    import java.awt.*;
    import java.util.*;
    import java.sql.*;
    import java.net.*;
    import java.io.*;
    public class CreateCoffees extends Applet
         String url = "jdbc:oracle:thin:@localhost:1521:BD";
    Connection con;
    String createString = "insert into COFFEES " +
    "values('Pepe')";
    Statement stmt;
    TextArea textarea = new TextArea();
    public void init()
    setLayout(null);
         textarea.setBounds (10,50,280,150);
         textarea.setText("Empieza");
         add(textarea);
         try
    Class.forName("oracle.jdbc.driver.OracleDriver");
    } catch(java.lang.ClassNotFoundException e) {
         System.err.print("ClassNotFoundException: ");
    System.err.println(e.getMessage());
    textarea.setText(e.getMessage());
    try {
    con = DriverManager.getConnection(url, "SYSTEM", "manager");
    stmt = con.createStatement();
    stmt.execute(createString);
    stmt.close();
    con.close();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    textarea.setText(ex.getMessage());
    }

    A no suitable driver error means that either your connection string is incorrect or you are not loading the driver (or failing to load it and ignoring the exception.)
    Presumably you have already dealt with the problem of delivering the oracle zip file with your applet?
    And you are not getting the not found exception in your code?

  • I need help with Applets and Multithreading

    [hello all.  first time poster. big fan of java.]
    now to the important matter: Applets and Threads
    =======================================
    1) I have an applet with that implements the runnable interface, and has one thread (and a simple animation). If I try to view this applet in the applet viewer with JGrasp, it spits an insane error telling me
    "java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)"
    but, if I run the applet through a web browser, by putting it in an html document, it runs correctly, without error
    What on earth is wrong, and how do I fix it?!?
    2) I want to put 2 threads in my applet?
    If I implement the Runnable interface, I can only have one Run() method in my applet, right?
    So how do I define behaviour for 2 threads when I only have one run method in which to define the behaviour? Can I use two threads with the runnable interface, or do I have to make objects of my own defined thread classes?
    3) I tried to make 2 threads in my applet by creating my own thread classes, and instantiating them in my applet (instead of implementing the runnable interface).
    I still get the same insane error as I mentioned in my first point (which I expected), except now, the applet won't work even when viewed through a web browser!!
    Please please help me. I am frustrated beyond belief (at what is probably a very simple problem)
    I have searched and searched all over and found no answers on this

    If I try to view this applet in the applet viewer with JGrasp, it spits an insane error telling me
    "java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup)"Don't know anything about JGrasp, but it runs with pretty tight security - thats what this insane error is all about. Use the appletviewer or a browser.
    If I implement the Runnable interface, I can only have one Run() method in my applet, right?Correct
    So how do I define behaviour for 2 threads when I only have one run method in which to define the behaviour?
    Can I use two threads with the runnable interface, or do I have to make objects of my own defined thread classes?You can create two Runnable implementations (classes) in your applet.
    example (missing code)
    class MyApplet extends Applet {
      void doSomething() {
      void doSomethingElse() {
      void startThreads() {
        Thread t = new Thread(new Runnable() { public void run() { doSomething();}});
        t.start();
        t = new Thread(new Runnable2());
        t.start();
      class Runnable2 implements Runnable {
         public void run() {
           doSomethingElse();
    }If the above seems confusing, read up on anonymous and inner classes.
    3) I tried to make 2 threads in my applet by creating my own thread classesTry not subclassing thread - this causes a security check

  • Multiple instances of the same applet loaded causes problem

    I have a java applet that has several classes in the project. The applet has a JTable a JButton and a JLabel control. The applet is displayed within an HTML page. The problem is that if a user opens the same html page more than once with the applet in it, only the last applet loaded receives the screen updates.
    For example in one senario. I have an error message that displays in the Label control once they click on the button.
    The user opens the html page and the applet is loaded (window 1). The user then opens the same html page again (window 2) with window 1 still open. If the user clicks on the Button in window 1, the error message is displayed in the window 2 applet.
    Originally I had some static variables. Thinking it was being used globally by the JVM so I removed all of them and it still happens. I have tried using both the Applet and Object tag. But it still happens.
    Has anyone experienced this before? Any suggestions on how to make the applet update the instance that recieved the events and not just the last one that was loaded?

    You need to look at applet classloader issues. If applets have the same archive list and come from the same codebase, they have the same classloader. A class is namespaced by it's class + classloader. Any statics in a class with a classloader will be shared. If you instead make it such that your applets have unique classloaders (which you can't change for unsigned applets by yourself) by changing the codebase, that would be one solution.
    For other solutions, I recommend searching the forum. This issue comes up a lot.

Maybe you are looking for