Reputation: 33
Connection baglanti=(Connection)DriverManager.getConnection("jdbc:"+"mysql://localhost:3306/mydatabase?useUnicode=true&"+";characterEncoding=latin5","id","password");
Now, how to connect my websites mysql database from java program ? I connect MAMP servers mysql database but I cant connect my website database.
localhost -(instead)-> www.mywebsite.com is that true ?
And sorry for my english.
I figured it out, cPanel -> "Remote Database Access Hosts"
Upvotes: 0
Views: 1373
Reputation: 9708
you can use this code but to get better solution you must describe the problem or error exactly
String url = "jdbc:mysql://localhost:3306/";
String db= "db1";
String user = "user";
String pass = "pass";
Connection conn = DriverManager.getConnection(url+db,user,pass);
Upvotes: 1
Reputation: 667
Seems like JDBC connection string you're creating at getConnection() method is correct.
If your MySQL DB is located at same computer as Java application you can use localhost, otherwise use ip address of computer where MySQL is installed.
By running netstat -tupano | grep mysql
you can ensure that MySQL listens network socket.
Upvotes: 0