Can NOT connect to Mysql

Hi All
Below is my code for a simple form which connects to Mysql. Problem is if I just connect to database and not have any other code (i.e Form) that works fine but when I try to connect with the form code, it gives me errors. why??? some help will be greatly appreciated thank you.
Zed
code
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Driver;
public class PersonalInfo extends Frame {
Connection conn=null;
Panel Np = new Panel();
Panel Sp = new Panel();
public PersonalInfo(){
NorthPanel();
add(Np,BorderLayout.NORTH);
SouthPanel();
add(Sp,BorderLayout.SOUTH);
public void NorthPanel(){
Label LfirstName = new Label("First Name");
TextField TfirstName = new TextField(20);
Label LlastName =new Label("Last Name");
TextField TlastName=new TextField(20);
Np.setLayout(new GridLayout(2,1));
Np.add(LfirstName);
Np.add(TfirstName);
Np.add(LlastName);
Np.add(TlastName);
public void SouthPanel(){
Button Submit=new Button("Submit");
Sp.add(Submit);
Button Cancel = new Button("Cancel");
Sp.add(Cancel);
public static void connect(){
System.out.println("MySQL Connect Example");
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String userName = "c3031843";
String password = "vw84a3";
String driver = "com.mysql.jdbc.Driver";
try {
Statement stmt;
ResultSet rs;
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("URL: " + url);
System.out.println("Connection: " + conn);
System.out.println("Connected to the database");
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * " + "from category");
System.out.println("Display all results:");
while(rs.next()){
int Int= rs.getInt("cat_id");
String name = rs.getString("category");
System.out.println("\tid= " + Int + "\tstr = " + name);
}//end while loop
conn.close();
System.out.println("Disconnected from database");
catch (Exception e) {
e.printStackTrace();
public static void main (String[] args) {
System.out.println("Personal information");
PersonalInfo PerInfo = new PersonalInfo();
PerInfo.setTitle("Personal Information");
PerInfo.setSize(400,200);
PerInfo.setVisible(true);
connect();
PerInfo.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}Errors Code
Personal information
MySQL Connect Example
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at PersonalInfo.connect(PersonalInfo.java:52)
at PersonalInfo.main(PersonalInfo.java:80)
Process completed.

Warnerja thanks for your reply, like I said if I don't use any other code and just use like this;
import java.sql.*;
public class MysqlConnectionTest {
public static void main(String[] args) {
System.out.println("MySQL Connect Example");
Connection conn=null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "test";
String driver = "com.mysql.jdbc.Driver";
String userName = "c3031843";
String password = "vw84a3";
try {
     Statement stmt;
     ResultSet rs;
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
System.out.println("URL: " + url);
System.out.println("Connection: " + conn);
System.out.println("Connected to the database");
     stmt = conn.createStatement();
     rs = stmt.executeQuery("SELECT * " + "from category");
                System.out.println("Display all results:");
      while(rs.next()){
        int Int= rs.getInt("cat_id");
        String name = rs.getString("category");
        System.out.println("\tid= " + Int + "\tstr = " + name);
      }//end while loop
conn.close();
System.out.println("Disconnected from database");
catch (Exception e) {
e.printStackTrace();
}it works like charm so I don't understand why there are errors once I put rest of the code in.

Similar Messages

  • Database error #2002 can not connect local mysql server to socket through '/var/run/mysqld/mysqld.sock'(2) on mac os x 10.9.2

    Dear Fellas:
    I received "database error #2002 can not connect local mysql server to socket through '/var/run/mysqld/mysqld.sock'(2)" on mac os x 10.9.2.
    mysql info:
    ps -ef | grep mysql
        0    66     1   0 11:06AM ??         0:00.04 /bin/sh /usr/local/mysql/bin/mysqld_safe --user=mysql
       74   225    66   0 11:06AM ??         0:02.50 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/Chuans-MacBook-Pro-2.local.err --pid-file=/usr/local/mysql/data/Chuans-MacBook-Pro-2.local.pid --socket=/var/run/mysqld/mysqld.sock
      501   952   947   0  3:52PM ttys000    0:00.00 grep mysql
    Please help!!

    Fascinated and guessing:
    Something related to sock(2) because that's not part of your copied info. I'm thinking you've doubled up on sockets and the second socket doesn't exist, meaning you should be connecting to the first socket "mysqld.sock" whether automatic or not.
    I've only used GUI tools on purpose, so does this mean you've already got MySQL running and you tried to launch it again manually? Perhaps you already have one instance of a db and you're trying to launch a second instance, and the two can't coexist with a single user local db?
    Assuming this is all local, I'd shut down the db service and restart it, out of hand. I've seen similar messages when I set the db to start up on boot, and it didn't finish shutting down when I tried to restart it manually. Usually the GUI won't let me turn it on because it reports it's already running, but in that case it hadn't finished performing what the GUI was reporting.
    Just speculating.

  • Can not connect to mySql database

    Hi,
    I created a database with tables on my company server.
    I programed a java GUI application to communicate the this database, i.e userlogin.java. Everything works perfectly. However, when I cretate a jnlp for this application, changing the and upload it as well as necessary java jar file to the company web space. Tthe program runs with Java web star but it seems that it get no data from the database. For example, when I type my username and password, it shows that there is no such username in the database which in fact my username exist in the database.
    Thank you.

    Thank you for your answer.
    I'm very new to mySql as server. When I was assigned to write the application, the administrator has set up mySql database in the company web server for my application. My program runs very when using my workplace desktop with java web start or run with java web start in netbeans (all paths should be link to my desktop hard disk, i.e. users/application/). I can not run the application at home because I can not access to the company intranet server (for security purpose). The problem happens when I post the application in the company web page (I have to modify all paths in jnlp file to the company web address). The program then runs without exception except it seems that it gets no data from the database.
    Please help me.
    Thank you in advance.

  • Can I connect to MySQL database

    sorry for my English...
    I'm absolutely new in Flex
    can I connect to MySQL database?
    I read here that I need to create a java class file and edit
    an xml to create connection to oracle, can I connect to MySQL
    server too, I think that the PHP-XML is too slow to work with lare
    amounts of data... so can you post me MXML, the XML, and the JAVA
    class file, with I will be able to send sql to mysql server and get
    the response?
    or FDS is a stand-alone SQL server?

    Flex is not a SQL server.
    The Flex SDK and compiler supports developing applications
    that run in the Flash player.
    Flex Data Services is deployed as a Java web application that
    simplifies integrating Flex clients with Java server-side resources
    (including interacting with SQL databases via Java).
    FlexBuilder is an IDE for developing Flex apps.
    I'd recommend spending some time browsing the Flex product
    area on adobe.com.
    Best,
    Seth

  • MySQL - Another 'Can't connect through mysql.sock' question...

    Hey, folks.
    So I'm trying to install MySQL to run with PHP on my PowerBook G4 (running 10.4.7, non-server edition) to use it to test out a shopping cart program for a website I'm building.
    I had it working as of Monday, when I installed it, got all the permissions set, built the necessary tables, and changed the root password (and logged in just to make sure it worked before retiring for the night)...but today I realized that I had somehow installed the wrong version of MySQL (I connected to it earlier today and discovered it was 4.026 - and I needed to be running MySQL 4.1.20, in order to be running the same version as my webhost).
    So I decided to upgrade. I downloaded and installed the 4.1.20 file, followed the directions about creating the system tables, changed permissions via sudo chown -R mysql:mysql data...and now, when I go to change the root user password (just to make sure it's still the same as it was), I get the following error:
    error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
    Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!
    This error also occurs when I try to simply startup MySQL. I also now find I can't connect via MySQL Admin, either - it gives me the same error. Pinging the host works, however.
    Sooo...anyone have any ideas? I've read up on the forums re: Apple changing the socket to /var/mysql/mysql.sock as of 10.4.4, but it seems that would have affected me earlier this week when I was running the previous version of MySQL, too (I certainly haven't upgraded the OS since then).
    Regardless, I can't connect through MySQL Admin using the /var/mysql/mysql.sock socket, anyway...nor the standard /tmp/mysql.sock.
    Any thoughts on what might be causing this? I should confess, I'm well-versed in DOS (ugh), but UNIX is not really my strong suit, so I'm still figuring out how to get around in the Terminal...
    Thanks so much for any input you can give me!
    (Oh, one more thing, since it'll probably come up - I'm not currently connecting via PHP, but I will be eventually. Right now, I just want to be able to change my root password, and login from the Terminal)!
    Thanks again!\
    PowerBook G4 1GHz 15   Mac OS X (10.4.7)  

    Alright, folks.
    Somehow my computer has fixed itself. After wiping the mysql directories entirely, then reinstalling, I was still getting the same error.
    After going back to the original "MySQL-On-Mac" site at Marc Liyanage's entropy.ch site & following some of the instructions there, somehow my problem seems to have fixed itself.
    I wish I could tell you what the solution was (to benefit anyone else having this problem), but since I was simply following the unix commands listed there (without much explanation, at times, as to what they were doing), I just know that somehow it worked.
    (But if I had to make a guess, I think it had to do with starting the server via sudo ./bin/mysqld_safe &)...

  • Can not connect outside of Lan to with rtsp PVC2300

    I have the following cameras set up at my office
    1 - PVC2300
    2 - WVC54GC
    3 - AXIS 225FD
    I have a BEFSR81 Router
    I have a computer on Windows XP running the surv software to record.  Everything with that is good.
    I also have 2 desktops.
    I have been playing around with the rtsp feed with the pvc2300, but have run into a few problems.
    1(a).  I can not connect outside of the LAN with RTSP with either the VLC player or quicktime.  It connects and asks for a password and then just hangs.
    The PVC 2300 local address is 192.168.1.102 with ports 554, 5000-5010, and 6970-6999 forwarded on the router.  What am I missing?
    1(b) I can successfully connect with my blackberry bold, although when I try to change the default port (554) to something else (I would like to RTSP my the AXIS camera as well,  so I will need a different port) it connects on my bold, but then says server is unresponsive. What am I missing here?
    2.  The voice with the PVC 2300  using http outside of the LAN (internet) lags quite baddly and is choppy.  This happens without fail when I have all 4 cameras running, which I understand is upload bandwidth problem.  But it also happens when I connect to just the PVC2300.  I do have a connection to all 4 cameras inside the LAN to the XP running the surv software, but that is it. Is the my router acting buggy?  I have unplugged the router for 5 sec, and it fixed it for a while, but it always comes back.  I have donwloaded the latest firmware for the router and PVC 2300 and that didnt seem ot fix it either.  Suggestions?
    3.  This is more of a question.  I know the mobile streaming of the PVC 2300 does not include voice.  Is there an app or way that I can just get it to my Blackberry.  Even if I didnt get the video, voice is sometimes more important to me.
    I hope Ive been clear enough in my description, Im very self taught (google is amazing), but I am in no way a techy.
    Thank you in advace for your help.
    Colin

    Glad to hear you are successfully using the SWVMS16. That program is really cool and useful. I just cant tell you how that model of Linksys Router can work for you here (that is not a model we support on this community as its not small business)
    Regarding RTSP access, are you also including the mobile.sdp in the URL?
    RTSP:///mobile.sdp   I noticed in the camera GUI with the newer firmware, you can specify an access code under mobile settings after checking the enable mobile streaming box.  That word may be what you have to include, so check that too...
    Try this locally first and then remotely is the easiest way to see if you got it right, then it just becomes a routing or firewall issue to figure out.
    But your forwarded ports look right and should be opened.
    Under advanced settings, you can define an alternate HTTP, HTTPS or RTSP port

  • Can not connect computer to Cisco Connect -EA3500

    Can not connect computer to Cisco Connect -.Receive error msg 82BD0305. Reset to EA3500 to default and reinstalled software.

    Reading the manual it says the username is blank, password 'admin'.

  • Can not connect my wireless printer to the new router.

    Can not connect my wireless printer to the new router.

    Can you please provide details:
    1.  The make and model of printer
    2.  Make and Model of Wireless Router
    3.  Is your printer connection wireless to router or a cable to PC
    4.  What have you done or attempted to do to establish a connection?
    5.  Any further info to assist

  • Can not connect to Image Browser

    Can not connect to Image Browser. Try to open again but no results.

    Hi garyrandall,
    I'm sorry to hear of the difficulty you've encountered with the transfer of images from your Canon camera.
    Please reply with the Camera model you're using and the operating system on your computer.
    Please include any error messages you receive.
    We look forward to hearing from you!
    Richard
    Did this answer your question? Please click the Accept as Solution button so that others may find the answer as well.

  • Adobe cloud application manager - can not connect to internet

    To ADOBE - The Adode cloud Order no is DSSY006786009DT and is current
    The Adobe cloud application manager - can not connect to internet even though there is internet connection and says it might be time zone error but that is correct  - Sydney Australia
    Question:
         1. Is anybody else having this problem
         2. How do we fix
    I already changed the time zone east coast US - did not change anything
    Could it be a corrupt program - thus requiring to reinstall program Application manager
    I am using Windows 7.
    It has been like it for ten days - It asks to log in everytime I turn computer on
    All programs in Creative Cloud work
    Any suggestions and solution
    Online help and phone help had no solutions other than what I suggested - that is reload application manager
    Thanks for help
    Ian Cleland

    The Creative Cloud File Synching was just offline, should be online now again.
    See top off: http://forums.adobe.com/community/creative_cloud/creative_cloud_connection
    Maybe that was your problem.

  • I have an iPhone 4S I can not connect to iTunes to update apps?

    I have an iPhone 4S I can not connect to iTunes to update apps

    I have this issue, too. It seems that nobody has come up with a solution. My wife's ipad2 works fine. I have an iPad 1

  • I am trying to turn on iCloud, I get a message "can not connect to server". How do I connect to server?

    I can't get iCloud to turn on. When I try to start it I gat a message "can not connect to server". How do I start the cloud?

    So what model and year is your machine?
    Here are the requirements for ML:
    http://www.apple.com/osx/specs/

  • HT3986 I installed windows 7 to my macbook pro, but my mousepad does not work in windows 7 and also i can not connect my windows 7 to projector, but i can use my macbook's mouse pad and i can connect my mac to projector,so please help me for windows 7 pro

    I installed windows 7 to my macbook pro, but my mousepad does not work in windows 7 and also i can not connect my windows 7 to projector, but i can use my macbook's mouse pad and i can connect my mac to projector,so please help me for windows 7 problem

    i try to download now, do you think when i download and install the windows support software, can i fix the problem?

  • HT4623 Please help. My iphone can not connect to SIM card , I tried many times there is no hope.

    Today I updated my iphone , but when it finished , it can not connect with my SIM card I do not know why?

    What is the exact error message? Does it say that there is no SIM, or does it say that the SIM is unsupported or invalid?

  • I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    Have you tried repairing disk permissions : iTunes download error -45054

Maybe you are looking for

  • Why does the new CVI adapter not put the contextCVI parameter?

    Hi, With good old 2.0 prototype you could not specify arguments and you always used the parameters tTestData and tTestError. Now, with the TS3.x the recommended prototype is the new one. If I specify the standard prototype it puts some arguments whic

  • Validation currency field

    I want to create a validation. The field should be checked in max. two decimal places,not null, > 0 and in numeric. I tried this: if v('P42_BESTAND') is not null and v('P42_BESTAND') > 0 then return true; else return false; end if; exception --'when

  • Recovery mode, i have tried almost everything, help

    I need some help. My ipad cant get out of recovery mode, and nothing happends when i connect it to my computer (i have itunes installed, and the newest verson of it) I have tried all links on google, youtube... but i cant find anything that works. Pl

  • Require details or list of seeded reports and import programs in fusion HCM

    Hello All, Kindly provide me the list of seeded reports and Import programs available in Oracle Fusion HCM . Regards, S Rao

  • Soft returns not importing

    Hi. I recently impoterd a Frame 7.1 Chapter into RoboHelp HTML 8.0 and everything worked okay with the exception of soft returns. For some reason it didn't import these and I was left with large strings of test which I had to fix by hand. Any ideas?