Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 24th, 2001, 06:03 PM
Zitan Zitan is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2001
Location: New Zealand
Posts: 638 Zitan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 10 sec
Reputation Power: 8
JDBC : MySQL Connection

Greetings All,

I'm trying to use the mm.mysql.Driver to connect from JDBC to MySQL. I load the driver okay, but then get the following error message:

PHP Code:
 SQLExceptionCannot connect to MySQL Server on localhost:3306  Is there a MySQL Server running on the machine/port you are trying to connect to


What port should I be connecting on? Do I need to configure JDBC or MySQL in someway? Any suggestions are very welcome.

Thanks,
Z.

Reply With Quote
  #2  
Old August 25th, 2001, 08:11 AM
Yawmark's Avatar
Yawmark Yawmark is offline
Feelin' Groovy
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Aug 2001
Location: WDSMIA
Posts: 7,627 Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level)Yawmark User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 1 Day 14 h 12 m 21 sec
Reputation Power: 1344
Send a message via ICQ to Yawmark Send a message via MSN to Yawmark
How are you trying to connect (i.e. what commands are you using)?
__________________
Yawmark
class Sig{public static void main(String...args){\u0066or(int
\u0020$:"vÌÈÊ\"¤¾Àʲ¬Æ\"v¤Î¤\"²¤¨¸¬Æ".to\u0043h\u0061rArray()
)System./*goto/*$/%\u0126//^\u002A\u002Fout.print((char)(($>>
+(~'"'&'#'))+('<'>>('\\'/'.')/\u002Array.const(~1)\*\u002F)));}}

Reply With Quote
  #3  
Old August 25th, 2001, 06:21 PM
Zitan Zitan is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2001
Location: New Zealand
Posts: 638 Zitan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 22 m 10 sec
Reputation Power: 8
Greetings All,

I've included my basic class below, but I know it works because I tried it locally! So if anyone's want to know how to connect MySQL with JDBC here's some basic code, I'm using the MM driver, which you need to install and copy to the /jdk/jre/lib/ext directory. My problem is definately from the MySQL end, I cannot get a remote connection going and I really need to

Any help is appreciated,
Z.


java class connect
(I get the error just after connecting to MySQL hits the screen)

PHP Code:
 import java.sql.*;

public class 
connect
{
    public static 
void main(String[] Args)
    {
          
System.out.println("Loading Driver.");
           try {
                  
          Class.
forName("org.gjt.mm.mysql.Driver").newInstance();
        }
          catch (
Exception E) {
          
System.err.println("Unable to load driver.");
          
E.printStackTrace();
        }

        try {

    
String url="jdbc:mysql://localhost/weblearn";
   
System.out.println("Connecting to MySQL.");
   
Connection Conn DriverManager.getConnection (url"root""dalek$");
           
System.out.println("connected!");
         
Statement Stmt Conn.createStatement();
ResultSet RS Stmt.executeQuery("SELECT Name from test");
           while (
RS.next()) {
                 
System.out.println(RS.getString(1));
           }

        
// Clean up after ourselves
           
RS.close();
           
Stmt.close();
           
Conn.close();
           }
            catch (
SQLException E) {
              
System.out.println("SQLException: " E.getMessage());
              
System.out.println("SQLState:     " E.getSQLState());
              
System.out.println("VendorError:  " E.getErrorCode());
            }
 }



Reply With Quote
  #4  
Old August 29th, 2001, 12:09 AM
yangontha yangontha is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: Singapore
Posts: 3 yangontha User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Do you set up user on mysql table?

If so you may need to use
"jdbc:mysql://localhost/databasename?user=username"

Reply With Quote
  #5  
Old August 31st, 2001, 04:34 PM
DC Dalton DC Dalton is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2001
Location: NE Pa.
Posts: 96 DC Dalton User rank is Private First Class (20 - 50 Reputation Level)DC Dalton User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 29 m 32 sec
Reputation Power: 8
NOt sure but this might help

I think your problem may be with the way your presenting the connection to the db....I had quite a few problems when i first started but then settled on this config & havent had a problem since....of course this is single connection stuff which should be avoided in favor of connection pooling if you expect mulitple db connections. Anyways, here's how I do it:

Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/[dbName]?user=[dbUserName]&password=[dbPassWord]");
Statement stmt = conn.createStatement();

Hope this helps

Also your gonna have to catch 3 exceptions here or the compiler screams. They are InstantiationException, ClassNotFoundException & IllegalAccessException

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > JDBC : MySQL Connection


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway