I have an sql database called roottesting and I manage it at the ip 192.168.1.121. I also have a simple java application that connects to it (or rather, is supposed to connect to it) over the Internet with a user named ‘user’ that has a host of ‘%’, which I know will make it usable for any computer that uses it. Here is the method in which my program connects to the database:
public void addTestEntry(TestEntry testEntry) throws ClassNotFoundException, SQLException { tests.add(testEntry); Class.forName("com.mysql.jdbc.Driver"); String url = "jdbc:mysql://192.168.1.121/roottesting"; con = DriverManager.getConnection(url, "user", "S@cajaw3a"); PreparedStatement statement = con .prepareStatement("insert into tests values(?, ?, ?)"); statement.setString(1, testEntry.getName()); statement.setInt(2, testEntry.getCorrect()); statement.setInt(3, testEntry.getIncorrect()); statement.executeUpdate(); con.close(); }
This will work every time I download the program on another computer on my home network, Beigecedar, but when I try to do it on another network, like my school’s network, it does not work and gives that standard message that signals that the database could not be found. Can anyone give me a suggestion about how to connect to my database over the Internet, no matter what network the computer running the program is in?
Advertisement
Answer
The IP Address you are connecting to is what is called a Reserved IP Address
It is local to your network only ( 192.168.0.0/16 ). With that aside let’s address 2 things.
If you are allowed to connect to your own computer from the internet (IE: Firewall and ports open) then you can connect using your public IP Address
You also have to consider what ports your school allow to be open. They may very well block the ports required for you to make this connection.