Establishment of connection rejected (MySQL & Applet)
From: circuit_breaker (circuit_breaker_at_canada.com)
Date: 04/24/04
- Previous message: Peter L.: "Re: To JDO or not - that is the question"
- Next in thread: Bjorn Abelli: "Re: Establishment of connection rejected (MySQL & Applet)"
- Reply: Bjorn Abelli: "Re: Establishment of connection rejected (MySQL & Applet)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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" );
- Previous message: Peter L.: "Re: To JDO or not - that is the question"
- Next in thread: Bjorn Abelli: "Re: Establishment of connection rejected (MySQL & Applet)"
- Reply: Bjorn Abelli: "Re: Establishment of connection rejected (MySQL & Applet)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|