Establishment of connection rejected (MySQL & Applet)

From: circuit_breaker (circuit_breaker_at_canada.com)
Date: 04/24/04

  • Next message: SMMT: "DBF (NTX,CDX) JDBC Free Driver"
    Date: 24 Apr 2004 14:25:16 -0700
    
    

    Hi,

    The following code works as an application but not as an applet on the
    localhost.
    The error is: "java.sql.SQLException: Data source rejected
    establishment of connection, message from server......Host
    192.168.0.72 is not allowed to connect to this MySQL server".

    I'm trying to run it from the server (localhost) and from another
    machine on the network but the error is the same (the IP address
    change of course). Is the problem a Java security issue or is it on
    the MySQL server?

    Here's the code:

    Application version (works)
    ---------------------------
    public class connectmysql
    {
            public static void main( String[] args )
            {
                    ResultSet rs;
                    Connection conn = null;
                    String url = "jdbc:mysql://localhost/Inventory";
                    String userName = "iuser";
                    String password = "mypass";

                    try
                    {
                            Class.forName ("com.mysql.jdbc.Driver").newInstance();
                            conn = DriverManager.getConnection (url, userName, password );
                            System.out.println ("Connected" );

                            Statement s = conn.createStatement();
                            String sql = "SELECT * FROM categories";

                            rs = s.executeQuery( sql );
                            while (rs.next() )
                            {
                                    System.out.println( rs.getString( "category_name" ) );
                            }
    ...
    ------------------------------

    Applet version:
    --------------

    public class sqlapplet extends JApplet
    {
            public JFrame frame;
            public void init()
            {
                    frame = new myFrame();
                    frame.setSize( 200, 200 );
                    frame.setTitle( "Applet Test on Linux with MySql");
                    frame.show();
    // new DatabaseConnection();
            }
    }

    class DatabaseConnection
    {
            static String driver = "com.mysql.jdbc.Driver";
            DatabaseConnection()
            {
                    try
                    {
                            Class.forName( driver );
                    }
                    catch (Exception e)
                    {
                            return;
                    }
            }
    }

    class myFrame extends JFrame
    {
            private JPanel myPanel;
            private JTextField jtf;

            static String driver = "com.mysql.jdbc.Driver";
            static String url = "jdbc:mysql://localhost/Inventory";
            //Connection conn = null;

            static String user = "iuser";
            static String password = "ipass";

            private ResultSet rs;

            myFrame()
            {
                    myPanel = new JPanel();

                    Container contentPane = getContentPane();
    // contentPane.setLayout( new( BorderLayout() ) );

                    myPanel.add( jtf );
                    contentPane.add( myPanel );

                    try
                    {
                            Class.forName( driver ).newInstance();
                            jtf.setText("Driver loaded" );
                            try{

                            Connection conn =
    DriverManager.getConnection("jdbc:mysql://localhost/Inventory?user=iuser&password=mypass");
                            }

                            catch( SQLException e)
                            {
                                    jtf.setText( e.toString() );
                                    return;
                            }
                            jtf.setText("Connected" );


  • Next message: SMMT: "DBF (NTX,CDX) JDBC Free Driver"

    Relevant Pages

    • Re: J# app and J# Browser Control behave differently
      ... When run as a browser control the http request is formatted as follows: ... public class AppletTest extends Applet ... >> private void connect ...
      (microsoft.public.dotnet.vjsharp)
    • AccessControlException when running with applet
      ... as a panel and several other classes. ... the Panel, instead of the driver. ... When I run the Applet, ... public class AppletPotter extends JApplet ...
      (comp.lang.java.programmer)
    • Re: Illegal start of type...
      ... with a samples source CD or at least with a link to these samples on the ... > public class Hello { ... > Connection connection; ... > public void connectToDB() { ...
      (comp.lang.java.help)
    • Re: incompatible types?!
      ... > public class createTables { ... > private Connection connection; ... > It uses my DataBaseConnection connection class below (this class works ... > public class DataBaseConnection { ...
      (comp.lang.java.help)
    • Re: Getting data in class hierarchy (C#)
      ... Connection is reused while it is not being active. ... > If I want just the MoreSpecficUser data then I just call its Load() ... > public class MoreSpecficUser: User ...
      (microsoft.public.dotnet.framework.adonet)