aspose file tools*
The moose likes JDBC and the fly likes how to connect MySql Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to connect MySql" Watch "how to connect MySql" New topic
Author

how to connect MySql

Dorj Galaa
Ranch Hand

Joined: May 29, 2001
Posts: 113
Hi I'm installed MySql server and client on Win98 and program is working Ok; code is
import java.sql.*;
//import org.gjt.mm.mysql.*;
public class MySQL
{
public static void main(String args[])
{
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
Connection mysql=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mysql?user=root&password=");
Statement st=mysql.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String Query="select host,user,password from user";
ResultSet Result=st.executeQuery(Query);
while (Result.next())
{
System.out.println(Result.getString(1)+" "+Result.getString(1)+" "+Result.getString(1));
}
Result.close();
st.close();
mysql.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
If i access to remote machine (e.g IP=192.168.0.58) connection is
Connection mysql=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mysql?user=username&password=password"); but have Access denied for username.
How to connect remote server?


Senior software engineer
Robert Brunner
Ranch Hand

Joined: Jul 18, 2001
Posts: 49
Originally posted by Dorj Galaa:

Connection mysql=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mysql?user=root&password=");
If i access to remote machine (e.g IP=192.168.0.58) connection is
Connection mysql=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/mysql?user=username&password=password");

Well, you have different username/password combinations in your connect statements. If that is not the problem, the first thing you should check is that your username/password actually does work on the remote database
 
Don't get me started about those stupid light bulbs.
 
subject: how to connect MySql