0

So normally, you would use this:

 Connection conn = DriverManager.getConnection("jdbc:mysql://[ip:mysqlport]/[databasename]?user=[user]&password=[password]");

However, I need to connect to an IP using a specific port in addition to specifying the MySQL port as well. I tried ip:serverport:mysqlport, but it didn't work.

Edit: Nevermind, I was misunderstanding something.

Bluejay
  • 341
  • 1
  • 10
  • What do you mean by "in addition", a connection to mysql will only be on one port. do you mean you are using a proxy or something? – Tea Curran Feb 01 '17 at 09:01
  • I find it unclear what you are trying to do. You can only connect to one port. – Mark Rotteveel Feb 01 '17 at 09:20
  • Nevermind, I was misunderstanding something. – Bluejay Feb 01 '17 at 09:50
  • It is either a direct connection then you have only 1 port. Or you should be using a ssh tunnel and thus should actually be connecting to localhost, in which case you'd want http://stackoverflow.com/questions/1968293/connect-to-remote-mysql-database-through-ssh-using-java – Redlab Feb 01 '17 at 09:51

1 Answers1

2

Try structuring it like this and see if it helps

Connection conn = 
DriverManager.getConnection("jdbc:mysql://192.168.0.1:5000/myDB", "admin", "admin");
Youcef LAIDANI
  • 55,661
  • 15
  • 90
  • 140
Jacques Ramsden
  • 801
  • 5
  • 20