-1

Is there any programs that lets me create my own MySQL database, perferably with phpmyadmin. And that lets me connect to the database from the outside, and lets me edit it. Like from java, using JDBC.

I've tried wamp, but i didn't seem to be able to connect to it using java.. which was a bummer. If it's possible please tell me how.

Considering trying xampp, not sure if it'll work though..

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • 1
    WAMP and XAMP are more than just MYSQL. And if you want to connect from Java to your MySQL database, use the proper JDBC driver (jar) and read a tutorial on such topic. – Luiggi Mendoza Jul 13 '14 at 17:29

1 Answers1

0

You can use wamp or xampp both to create database and manage it from phpmyadmin and connect it using java. just download wamp or xampp and set it up for use. create your database and tables as per your requirements. then you can use following code snippet to connect it from java if you are using wamp.

Connection connection;

String dburl = "jdbc:mysql://localhost/YOUR_DATABASE_NAME";
String user = "YOUR_USER_NAME";     //this is by default 'root' in wamp
String password = "YOUR_PASSWORD";  //this is by default blank in wamp
//following line will establish the connection
connection = DriverManager.getConnection(dburl, user, password);

//You can use following method to retrieve data from the database tables.

Statement statement = connection.createStatement();
String query = "SELECT * FROM YOUR_TABLE_NAME";
//Below line will return resultset of the select query. it is a kind of array set.
ResultSet result = statement.executeQuery(query);

if(connection != null)
      connection.close();

NOTE: As you have already mentioned about JDBC in your question I assume you know how to add JDBC library to your existing project. If you don't you can refer to eclipse help here or netbeans help here.

UPDATE: following the answer here and here below could be the reasons and solution, double check that the database exist and the name is exactly the same when you access it.

You should also close a connection once you use it, refer to the updated code above.

If you get a SQLException: Connection refused or Connection timed out or a MySQL specific CommunicationsException: Communications link failure, then it means that the DB isn't reachable at all. This can have one or more of the following causes:

  • IP address or hostname in JDBC URL is wrong.
  • Hostname in JDBC URL is not recognized by local DNS server.
  • Port number is missing or wrong in JDBC URL.
  • DB server is down.
  • DB server doesn't accept TCP/IP connections.
  • DB server has run out of connections.
  • Something in between Java and DB is blocking connections, e.g. a firewall or proxy.

To solve the one or the other, follow the following advices:

  • Verify and test them with ping.
  • Refresh DNS or use IP address in JDBC URL instead.
  • Verify it based on my.cnf of MySQL DB.
  • Start the DB.
  • Verify if mysqld is started without the --skip-networking option.
  • Restart the DB and fix your code accordingly that it closes connections in finally.
  • Disable firewall and/or configure firewall/proxy to allow/forward the port.
Community
  • 1
  • 1
madteapot
  • 2,208
  • 2
  • 19
  • 32
  • i have something like this, but i get the error msg "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure" And everything is set up perfectly so i don't know what could be wrong.. the error msg leads me to the connection part.. – user3807261 Jul 13 '14 at 18:01
  • what's that variable s? – user3807261 Jul 13 '14 at 18:21
  • Ohh sorry about that it should be `statement` not s – madteapot Jul 13 '14 at 22:09