Results 1 to 3 of 3
  1. #1
    SirVyvin is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default MySQL connection tutorials?

    Ok so I have searched google for a few days now trying to find a good tutorial and even a good example, and have turned up nothing that just shows a working example (as I learn by seeing a working example of something). I also searched the forums for something and nothing came up that really helped. Can someone give me a link to a site that has a complete working connection example, or to a post in the forums that has a working example, or post one here?

    Thanks in advance.

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power

  3. #3
    SirVyvin is offline Member
    Join Date
    Dec 2011
    Rep Power

    Default Re: MySQL connection tutorials?

    I realise it has been a bit, but been very busy with stuff because Christmas is over, finally got back around to this. I took a while trying to understand the trail provided above with no success. So I asked my cousin if he happened to know JDBC and luckily he did and gave me a site that had a great working example for people who learn by those like me.

    The tutorial can be found here.

    I have posted an example I use myself in case you don't wish to go to the site. Also make sure your database host allows remote connections (won't work otherwise)! You must also have the MySQL JDBC library (?) in your class path. I use Netbeans 6.9.1 so I right click on the project and choose Libraries and add it to the compile tab.

    Java Code:
    import java.sql.*;
    public class HighScores {
        Connection conn = null;
        public HighScores() {
            /*constructor does nothing for my project but you can make it do something*/
        public void connect() {
            try {
                String userName = "your_user";
                String password = "your_pass";
                String dbHost = "your_host" //don't put the 'http://', only put something like, or
                String dataBase = "your_dataBase"; //database name, not the table
                String url = "jdbc:mysql://" + dbHost + "/" + dataBase;
                conn = DriverManager.getConnection(url, userName, password);
                System.out.println("Database connection established");
            } catch (Exception e) {
                System.err.println("Cannot connect to database server\n" + e.getMessage());
        public void close() {
            try {
            } catch (Exception e) {
                System.err.println("If you see this, well, you ****ed up big time let me tell you.\n" + e.getMessage());

Similar Threads

  1. Connection with MySQL
    By Amit20 in forum JDBC
    Replies: 18
    Last Post: 09-20-2011, 04:37 PM
  2. connection my mysql
    By pranjul137 in forum New To Java
    Replies: 5
    Last Post: 04-06-2010, 08:26 PM
    By tugalsan in forum JDBC
    Replies: 2
    Last Post: 03-21-2010, 09:46 PM
  4. Java-mysql connection
    By Kligham in forum New To Java
    Replies: 16
    Last Post: 11-25-2009, 02:28 PM
  5. no mysql connection
    By scchia in forum New To Java
    Replies: 12
    Last Post: 07-19-2008, 07:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts