0

I've connected my really basic Java application to the Wamp server on my computer using the following code

try {  
        Class.forName("com.mysql.jdbc.Driver");  
        Connection connection = DriverManager.getConnection(  
                "jdbc:mysql://localhost:3306/project", "root", "password");

Obviously, this program runs on my computer, but no one else's, and I need to submit this as a project.

Is there anyway I can modify this part so that my partner and teacher can run the code from their computers, without having to download any special software, and access the database on my localhost? Possibly like replacing //localhost:3306 with //my IP address:8080?

All suggestions I've gotten involve networking, which I don't know anything about so I don't want to try and then mess up my computer unless I'm really sure

Things I've already looked in to, but aren't sure about:

  • C:/wamp/alias/phpmyadmin.conf and entering the line ALLOW (other person's IP)
  • team viewer (requires the other computer to use software other than my program)
  • opening my router port to take incoming requests

Anything'll help guys, even just confirming it can't be done without some networking. If it's something an inexperienced person can do, I'll take it.

6
  • 3
    Have you tried: //my IP address:3306? That assumes there aren't any firewall or routing issues. Commented Mar 13, 2014 at 14:40
  • 1
    If your teacher is making an assignment like this, then they probably have details on how you are going to submit your project that you may have missed. Commented Mar 13, 2014 at 14:43
  • See: stackoverflow.com/questions/12885836/… Commented Mar 13, 2014 at 14:46
  • @North If they should have the database on their own computer provide a way to configure the route (like a .properties file), if not you could consider using an embedded mysql server for your application, or find your external ip address whatsmyip.org and then open port 3306 on your router Commented Mar 13, 2014 at 14:58
  • I did try //my IP but it created some kind of loop back error when I ran it on my system so I couldn't be sure Commented Mar 13, 2014 at 16:33

1 Answer 1

1

Apart from what you have tried, you also need granting privileges to access your database.

Try granting privileges to users from other IP addresses.

Read documentation GRANT Syntax.

Example:

GRANT ALL ON test.* TO '%'@'localhost' ...
GRANT ALL ON test.* TO '%'@'%' ...
GRANT ALL ON test.* TO 'ravinder'@'192.168.1.105' ...
etc...

There are other forms of granting access to specific database object to specific or all users connecting from a specific computer or all.
I suggest you chose the one which is appropriate for your need.

But, keep in mind that '%'@'%' will allow all users from all systems.

After granting the privileges, change your dbURL value for connection string with your IP address.

Connection connection = 
DriverManager.getConnection(  
                "jdbc:mysql://your_system_ip_or_name_here:3306/project",
                "root", "password");

Deploy the regenerated app on desired systems and it should be working.

Sign up to request clarification or add additional context in comments.

2 Comments

I think I was unclear, when I said "Things I looked into" I meant those are things I read while looking for an answer, but they all required either a) the other person having a database server on their computer or b) opening a port which are things I DO NOT want to do. So are you saying just using GRANT alone will allow access without the other computer being on the same network, having a database, or my port being open?
You need option b, and grant as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.