Results 1 to 3 of 3
Thread: MySQL connection tutorials?
- 12-26-2011, 01:34 AM #1
Member
- Join Date
- Dec 2011
- Posts
- 5
- Rep Power
- 0
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.
- 12-26-2011, 05:08 AM #2
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Re: MySQL connection tutorials?
- 01-11-2012, 12:35 AM #3
Member
- Join Date
- Dec 2011
- Posts
- 5
- Rep Power
- 0
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 www.google.ca, or www.facebook.com String dataBase = "your_dataBase"; //database name, not the table String url = "jdbc:mysql://" + dbHost + "/" + dataBase; Class.forName("com.mysql.jdbc.Driver").newInstance(); 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 { conn.close(); } 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
-
Connection with MySQL
By Amit20 in forum JDBCReplies: 18Last Post: 09-20-2011, 04:37 PM -
connection my mysql
By pranjul137 in forum New To JavaReplies: 5Last Post: 04-06-2010, 08:26 PM -
TWO IPs FOR MY MYSQL CONNECTION
By tugalsan in forum JDBCReplies: 2Last Post: 03-21-2010, 08:46 PM -
Java-mysql connection
By Kligham in forum New To JavaReplies: 16Last Post: 11-25-2009, 01:28 PM -
no mysql connection
By scchia in forum New To JavaReplies: 12Last Post: 07-19-2008, 07:57 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks