This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to connect MySql
 
Similar Threads
while loop return only 1 row when it should return 2 rows
com.mysql.jdbc.exceptions.jdbc4.communicationsexception communications link failure
please I urgently need help
Newbie Java MySql question
Reading usersnames/passwords from file for database access