user1593149
user1593149

Reputation: 33

How can I connect to my website database? java

Connection baglanti=(Connection)DriverManager.getConnection("jdbc:"+"mysql://localhost:3306/mydatabase?useUnicode=true&amp"+";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

Answers (2)

Hamed Naeemaei
Hamed Naeemaei

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

kyberorg
kyberorg

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

Related Questions