Need help setting up JDBC with mySQL and Netbeans

I've successfully got mySQL up and running and created a few simple test databases. I've been following the instructions on this website (http://www.stardeveloper.com/articles/display.html?article=2003090401&page=1 ) to get JDBC working but have had little luck.
I've downloaded JDBC from mySQL website, extracted the mysql-connector-java-3.1.13-bin.jar file and changed the class path to :
C:\Program Files\Java\jre1.5.0_06\lib\ext\mysql-connector-java-3.1.13-bin
which is where I placed the .jar file.
I then used the following code provided on stardeveloper.com to test a connection with the test database.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JdbcExample2 {
  public static void main(String args[]) {
    Connection con = null;
    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      con = DriverManager.getConnection("jdbc:mysql:///test",
        "root", "secret");
      if(!con.isClosed())
        System.out.println("Successfully connected to " +
          "MySQL server using TCP/IP...");
    } catch(Exception e) {
      System.err.println("Exception: " + e.getMessage());
    } finally {
      try {
        if(con != null)
          con.close();
      } catch(SQLException e) {}
}It compiles but when run I get the error message :
java.lang.NoClassDefFoundError: testdatabase/JdbcExample2
Exception in thread "main"I assume this means that my classpath isn't setup correctly but I have no idea what's up and how to correct it.
Can someone PLEASE tell me how to setup jdbc and what I've done wrong.
Thanks in advance :)

Thanks for your reply. I've made some progress but I'm still having problems.
In mySQL I created a new user called uraknai with password n0121429 and granted them access to a test database I created called pet.
Then, in netbeans, I clicked the Runtime tab, clicked Databases and rightclicked Drivers and clicked Add Driver. I then added the driver mysql-connector-java-3.1.13-bin.jar. I then right clicked the newly added driver and selected the connect using option. I filled in the appropriate boxes clicked ok and it connected successfully.
Then, under the project tab, I right clicked the project name, clicked properties then clicked Libraries and added the .jar file mysql-connector-java-3.1.13-bin.jar
I then ran the following code to test the connection to the database:
import java.sql.*;
public class ConnectionTest {
    public ConnectionTest() {
    public static void main(String[] args)
        System.out.println("BEGIN CONNECTION TEST");
        Connection conn = null;
        try
               String userName = "uraknai";
               String password = "n0121429";
               String url = "jdbc:mysql://localhost/pet";
               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");
         finally
               if (conn != null)
                   try
                       conn.close ();
                       System.out.println ("Database connection terminated");
                   catch (Exception e) { /* ignore close errors */ }
}and get the message:
java.lang.NoClassDefFoundError: math/ConnectionTest
Exception in thread "main"
Java Result: 1when I run the code.
Can someone explin what I've done wrong and how to fix the problem.
Cheers.

Similar Messages

  • Need help for Flash quiz with score and timer

    Greetings, I need to urgently create a flash
    game with 10 questions, 3 answers per question. At the end of the
    quiz I need to get the time the quiz was completed for, what answers the player answered correctly and the time its completed into a database, + a couple of fields like name and phone that the user fills also needed to be added into db with the score and time. I need it by the end of tomorrow and I do realise i dont have the knowledge to make it, So if there is anyone that wishes to help or trade services I can give you back the favour by creating some html/css/web design content for you. Thanks in advance and please excuse me for my terrible english.

    download flash cs6 and use it to publish your ad or expand flash cc's publishing capabilites.  if you have a flash cc subscription you can download and use flash cs6 after logging into your cc acount.
    here's how to expand publishing capabilites of flash cc: http://forums.adobe.com/message/5511080#5511080#5511080

  • Need help setting up iSync with Palm

    So, I'm trying to set up my Palm Treo 650 to sync with something other than Palm Desktop -- either Entourage or iCal, I guess. But I'm in this loop where iSync can't find Palm Desktop's HotSync Manager, and the HotSync Manager doesn't list iSync in its conduit settings. I can't figure out how to get the two to recognize each other.
    When I select iSync > Devices > Enable Palm OS Syncing, I get an error message saying Hot Sync Manager has not been properly installed, etc. But it has. I've been syncing fine with Palm Desktop, I just don't like it and want to try something else.
    I think I have the latest versions of everything installed -- OS 10.4.5, iSync 2.1.1, Palm Desktop 4.2.1, Entourage 10.1.6, iCal 2.0.3.
    My Treo is syncing fine via both USB cable and Bluetooth.
    Any ideas? Thank you.

    Forgive my long-delayed response; I got busy with school and work. I have now been attacking this problem on and off, most recently for several hours today, and am slowly going insane.
    I managed to get everything we talked about here set up -- the Disabled Conduits folder, an iSync conduit in Hot Sync, my Palm device added and syncing with iSync ....
    I even got Palm info showing up in iCal. But I could not get Palm info imported into Entourage. The import wizard kept saying "the Palm Desktop file could not be found," or words to that effect.
    I reset ALL the applications permissions.
    I tried to install the latest version of Palm Desktop, 4.2.1 Rev D. over 4.2.1 Rev A (I assume, because it just said 4.2.1). Kept getting an error message at the final step in the installation process: "There were problems installing. Please try again.)
    So I tried to reinstall Palm Desktop from my installation CD, and got the same install error.
    So I deleted every vestige of Palm and Hotsync I could find on my computer, emptied the trash, and then tried to install the Palm Desktop CD. Same install error.
    I am able to install other types of software just fine; in fact, just installed an OS X security update this morning.
    This is driving me crazy. I don't know what to do. I am on Spring Break so I have some time to mess with my computer, but after tonight my Internet access will be spotty for the next week.

  • Need help to create file with name and current time stamp.

    I need to create .xlsx file exporting data from sql database and file name would be 'FileName' and current yyyymmdd. 
    I'm trying to use following code but it's keep saying  incorrect syntax near "+".
    EXEC p_CreateExcel 'sql64', 'NewFile', '\\hrfile1\Shared\Buying Report\NewFile'
    + CAST(YEAR(CURRENT_TIMESTAMP) AS VARCHAR)
    + RIGHT('00'+CAST(MONTH(CURRENT_TIMESTAMP) AS VARCHAR),2)
    + RIGHT('00'+CAST(DAY(CURRENT_TIMESTAMP) AS VARCHAR),2)+'.xlsx'

    This is what I have on EXEC p_CreateExcel
    USE [XePro01]
    GO
    /****** Object:  StoredProcedure [dbo].[p_CreateExcel]    Script Date: 02/26/2015 11:27:35 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[p_CreateExcel]
            @db_name varchar(100),
            @table_name varchar(100), 
            @file_name varchar(100)
    as
    --Generate column names as a recordset
    declare @columns varchar(8000), @sql varchar(8000), @data_file varchar(100)
    select 
            @columns=coalesce(@columns+',','')+column_name+' as '+column_name 
    from 
            information_schema.columns
    where 
            table_name=@table_name
    select @columns=''''''+replace(replace(@columns,' as ',''''' as '),',',',''''')
    --Create a dummy file to have actual data
    select @data_file=substring(@file_name,1,len(@file_name)-charindex('\',reverse(@file_name)))+'\data_file.xls'
    --Generate column names in the passed EXCEL file
    set @sql='exec master..xp_cmdshell ''bcp "set fmtonly off select * from (select '+@columns+') as t" queryout "'+@file_name+'" -c -t, -T -S'''
    exec(@sql)
    --Generate data in the dummy file
    set @sql='exec master..xp_cmdshell ''bcp "set fmtonly off select * from XeProgst01.dbo.'+@table_name+'" queryout "'+@data_file+'" -c -t, -T -S'''
    exec(@sql)
    --Copy dummy file to passed EXCEL file
    set @sql= 'exec master..xp_cmdshell ''type '+@data_file+' >> '+@file_name+''''
    exec(@sql)
    --Delete dummy file 
    set @sql= 'exec master..xp_cmdshell ''del '+@data_file+''''
    exec(@sql)
    GO

  • I need help setting up a wireless network and getting connected to the internet. I have a RCN cable modem now and tried to install a wireless linksys today and it was a disaster

    I have a MAC desktop and RCN cable that I have internet through now. I tried to set up a linksys wireless router today and could not get the network settings right, or figure out how to create the network, or get connected. I was successfull for only a few minutes because my phone and laptop had picked up the signal. However my desktop still would not connect to the internet. I had to restart my cable modem after because even after returning to directly inserting the desktop to the modem I could not get on the internet. I am able to get on now but would like to have wireless for my laptop and phone. Do I have to have an Apple router? Are there any easy steps I can take to set up a network without doing any damage to my desktop? I am so lost and have been getting pop ups and even my time changed.
    Please help a new person to Apple!

    why dont you go to linksys.com/downloads and get the quick install for your adpter

  • Need help setting up VPN with OS X Server 2.2

    I just bought OS X Server in the hopes that it would be a simpler way to set up VPN for use with my iPhone.  I've tried a couple third party VPN configuration tools before with older versions of OSX but was never able to get it working.  Now I'm running 10.8.2 and Server 2.2.  I've made some progress, but I'm not quite there yet.
    Here's what I have set up in the VPN window:
    And the user I created:
    The User services show that VPN is selected:
    I let the Server app configure my Airport Extreme, and it looks like it set up the port mapping:
    Here are my iPhone settings
    -Server is set to my iMac's public IP address assigned by my ISP
    -Password is the password I gave the user account
    When I turn the VPN on in the iPhone I get:
    "Connecting..."
    "Starting..."
    "Authenticating..."
    then an error:
    "VPN Connection
    Authentification failed."
    What am I missing?
    Thanks,
    Sean

    Hi,
    1701
    UDP
    L2TP
    l2f
    Mac OS X Server VPN service
    1723
    TCP
    PPTP
    pptp
    Mac OS X Server VPN service
    Try L2TP

  • Need Help Setting Up Chattermail with AT&T Yahoo Mail Account

    Ok... so I've spent half the day trying every possible permutation of my login, server name etc and I STILL can't get Chattermail to successfully log in.
    This is a paid Yahoo mail account.   The servers I succesfully use for my older 700w were:  incoming: pop.sbcglobal.yahoo.com, outgoing: smtp.sbcglobal.yahoo.com   
    I'm confused by the set up in chattermail.  It doesn't have the servers marked as "outgoing" and "incoming"  I've put the incoming  server name in the "define" tab and the outgoing in the "smtp" tab.
    I've tried both my entire email address and just the part before the "@" as my login.  I also have the ssl boxes checked because my system seems to be using those.
    I cannot get it to work.  Does anyone have any ideas? 
    Post relates to: Centro (Verizon)

    Have you checked the Website for Chattermail for help? 
    WyreNut
    Post relates to: Centro (AT&T)
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • Need help using school network with mail and ichat....

    so at my local community college where i go, they have free wireless as most colleges do. the first time i open safari on campus, it redirects me to a website where i have to log on the network using an email address. it then logs you on as a guest. when i am on their wireless i am unable to connect to ichat or retrieve my mail. being that the mail is more important to me i posted it in here. i have tried to get it to work numerous times and figured i would rather post here first before i go to the it guys here at school. any help would be great...thanks in advance!!!! off to class for a couple hours right now i will check back later to see if i can answer any questions that can help you guys help me figure this out...i feel like it should be simple to do, but starting to think that maybe it is not possible?

    yea i have the same problem in my college so if any one can help id appreciated

  • [SOLVED] Need help setting up cpufrequtils with Daemons.

    Hello all. I'm running into this problem setting up power management tools on a Thinkpad T30. I've added acpi-cpufreq and cpufreq_ondemand to the rc.conf daemons but during boot I get the following errors.
    /etc/rc.d/acpi-cpufreq: No such file or directory
    /etc/rc.d/cpufreq_ondemand: No such file or directory
    Last edited by philthy (2010-05-22 20:31:05)

    philthy wrote:
    evr wrote:acpi-cpufreq and cpufreq_ondemand are modules, they should be added in the modules section not the daemons section.  cpufreq should be added to the daemons array.
    Thanks for the reply. Lack of attention to detail on my part.
    no worries, glad to help

  • Need help Designing a Query -with RKFs and CKF or alternate

    Hi,
    Trying to create a query off a HR Headcount IC - to display number of top performing employees (based on appraisal attribute) by region and by function. The format is as follows:
    Created 3 RKF's in column structure where
    1RKF is KF "Employee Numbers" for characteristics restrictions of date range1, appraisal rating=1,2, employee status =active etc.
    2RKF is KF "Employee Numbers" for characteristics restrictions of date range1, appraisal rating=#, employee status =active etc.
    3RKF is KF "Employee Numbers" for characteristics restrictions of date range2, appraisal rating=1,2, employee status =active etc.
    1CKF is Boolean result of (1RKF OR (2RKF AND 3RKF)
    Was able to display correctly all top performing employees in the following format. When "Employee" was selected to row.
    Top Performer (CKF)
    Employee 1----
    1
    Employee 2----
    1
    Employee 3----
    1
    Employee 4----
    1
    Employee 5----
    1
    Employee 6----
    1
    Employee 7----
    1
    When tried to display the same by Region by Function or even by only Region (Row Char) it doesn’t work. Data is non-sensical.
    # of Top performers
    Region 1 -
    FunctionA----
    5
    Region 1 -
    FunctionB----
    2
    Region 1 -
    FunctionC----
    3
    Region 2 -
    FunctionA----
    4
    Region 2 -
    FunctionB----
    0
    Region 2 -
    FunctionC----
    7
    Region 2 -
    FunctionD----
    5
    Understand that the Boolean CKF is not working correctly. What am I doing wrong ? Please advice fix or alternates.
    Thanks.

    Hi Pradeep,
    not possible to use ranking since Appraisal rating is a characterstics not a key figure value. Any other suggestions..
    Thanks
    Arun

  • Need help setting up and configuring rsync

    Hello
    I need help setting up, or rather configuring rsync to sync data between my brand new iMac and my Macbook Air.
    Here is what I would like to:
    - I want all of the files on both machines to be an exact mirror or copy of each other. Basically I have an iMac for at home, and then a Macbook Air for the road.
    - The main folder on both Macs is called 'Sara' and I want the contents (mainly the 'movies' folder, 'music' folder, 'documents' folder and 'pictures' folder) to immediately sync up with each other when both of them are on my home network.
    - this means if I'm working on a file at home on my Macbook, it will immediately write to the same directory on my iMac and vice versa (if I'm working on file(s) on my iMac, it will immediately save the contents to my Macbook). This way, if I'm working on last minute project my iMac, and then have to head out the door to the airport, the file is immediately saved to my Macbook (no usb for USB transfer).
    - hopefully this makes sense??
    Any help is greatly appreciated!
    Thanks

    It's a lofty but unrealistic goal.  Rsync does not run automatically.  There is no realistic method of instantaneously synching two computers over the internet or even on a LAN.
    I would suggest you might try using Synk Pro which, in theory, can keep two devices in sync when they are both on the same network (and both have shared and mounted drives.)
    If you must do this with rsync then I suggest a Google search for rsync tutorials.

  • I need help syncing my contacts between Outlook and iPhone using iTunes. I followed the steps given and ended up with just email addresses showing in my contacts even though I have phone numbers and snail mail in my Outlook Contacts. Using  Windows 7

    I need help syncing my contacts between Outlook and iPhone using iTunes. I used the knowldge document and set it up to transfer my Outlook contacts to the iphone using itunes.
    In contacts on the iphone I only see the email addresses.
    Yet in Outlook I have email, snail mail and phone numbers.
    I followed the knowledge document from iphone.
    I did it once, didn't work so deleted all the contacts from the phone and tried again. Same result. I have a PC using Windows 7 64 bit.

    You can't access an Exchange account via ActiveSync with the Address Book and iCal on your Mac.
    You can access a MM account with Outlook on your PC at work and keep your MM email account server stored mailboxes synced between your PC at work, your iPhone, and the MM "cloud". Not sure about syncing MM contact info and calendar events with Outlook at the same time with an Exchange account.
    This will not provide for syncing your Exchange account contact info and calendar events with the Addresss Book and iCal on your Mac because the accounts are separate.
    You can access an Exchange account and a MM account at the same time with the iPhone's mail client, and sync contact info and calendar events over the air with both accounts at the same time. You can view combined contact info or separately for each account, and the same for calendar events.

  • I have a Steinberg MI4 and a Roland Fantom X7, and am trying to use my Fantom in Logic to record audio. Need help setting it all up using MIDI cables. Please help !

    I have a Steinberg MI4 and a Roland Fantom X7, and am trying to use my Fantom in Logic to record audio. Need help setting it all up using MIDI cables. Please help !

    Encryption wouldn't matter except for Wifi.
    While 10.2 might help, there's not much you can do on the Internet these days with less than 10.4.11
    Tiger Requirements...
    To use Mac OS X 10.4 Tiger, your Macintosh needs:
        * A PowerPC G3, G4, or G5 processor
        * Built-in FireWire
        * At least 256 MB of RAM (I recommend 1GB minimum)
        * DVD drive (DVD-ROM), Combo (CD-RW/DVD-ROM) or SuperDrive (DVD-R) for installation
        * At least 3 GB of free disk space; 4 GB if you install the XCode 2 Developer Tools  (I recommend 20GB minimum)
    http://support.apple.com/kb/HT1514
    http://www.ebay.com/sch/i.html?_nkw=mac+os+x+tiger+retail+10.4
    See Tom's, (Texas Mac Man), great info on where/how to find/get Tiger...
    https://discussions.apple.com/message/15305521#15305521
    Or Ali Brown's great info on where/how to find/get Tiger...
    http://discussions.apple.com/thread.jspa?messageID=10381710#10381710
    As far as Memory, that's sort of easy, find your eMac here...
    http://eshop.macsales.com/MyOWC/Models.cfm?Family=emac&sType=Memory
    As far as Hard Drive, it's not easy to replace the Internal drive, I'd maybe suggest an external Firewire drive to boot from...
    http://eshop.macsales.com/item/Other%20World%20Computing/MAU4S7500G16/

  • I can't connect to wifi network and bluetooth on iPhone 4S.  Need help.  Have already rebooted everything and reset network setting

    I can't connect to wifi network and bluetooth on iPhone 4S.  Need help.  Have already rebooted everything and reset network setting

    I have the same problem; tried a phone restore, both restoring data and setting up as new phone with factory settings, reset all settings, re-boot, remove apostrophe, put in fridge, you name it!
    I think there's quite a few iphone 4s users with the same problem!
    I called Apple they said it's a hardware problem, but it has worked for nearly two years; they say go to the Apple store and they can provide a replacement phone for approx. £150!
    I've been into the O2 shop where I bought it and they knew the problem exactly; said they had sent a few phones off for repair and had them back awith a report they cannot fix it because it's a software problem!
    An assistant in the shop had the same issues; logic says it's a software problem and hopefully Apple will fix it with a patch but at the moment they seem to be avoiding everyones comments!
    If anyone else has any ideas these would be appreciated?

  • I have tried everything I know to retrieve the iPhoto Library app.  I detest this new Photo app, which obviously wasn't designed with photographers in mind.  I desperately need help in retrieving the old app and have not been able to do it so far.

    I have tried everything I know to retrieve the iPhoto Library app.  I detest this new Photo app, which obviously wasn't designed with photographers in mind.  I desperately need help in retrieving the old app and have not been able to do it so far.  I have gone to my app folder and tried to update my iPhoto Library.  I have gone to my trash and brought it over to my desktop and still cannot use it.  Please help!

    Try this fix discovered by User photosb189:
    From Finder, hold down the option key on your keyboard and click on the Go menu at the top of the screen
    Select Library from the drop down menu
    Then navigate to Application Support > iLifeAssetManagement > assets
    Right click on the 'sub' folder and choose Compress
    Drag the resulting zip file to your Desktop (as a backup)
    Go to your System Preferences and choose iCloud
    Turn OFF the iCloud Photos option
    Go back to Library > Application Support and DELETE the iLifeAssetManagement folder
    Now, in System Preferences, turn the iCloud Photos option ON
    iPhoto should now be able to launch. Give it enough time to re-download your Photo Stream content. if you are missing any of your My Photo Stream photos (more than 30 days old), unzip the sub folder on your desktop and drag that into iPhoto.

Maybe you are looking for

  • How can I print a list of the apps I have on my iPad and iPhone ?

    I had to reinstall all my apps when I upgraded to the new iOS - while some were listed in my 'purchased' list a lot weren't and I had to go through all my iPhone apps to see what was missing. And my folders all vanished as well!  Any hints or tips be

  • Possible to rate limit console input?

    I built a tool that allows us to input device information such as IP, VLAN, etc, etc and this tool builds the entire config file that can be pasted into a switch/router.  The problem is that when I start getting down near the banner and motd sections

  • Biztalk 2009 with WCF adapter running on 64 bit

    Hi experts, I'm running a wcf adapter 64 bit send handler/host on biztalk 2009. Will it work? or does it require the adapter to be configured on 32 bit?

  • GR posting date

    Hi pls tell me from which table we can get GRposting date Regards Nair

  • BAPI for changing PRT link to operation in order in Plant maintenance...

    Hello, I am working on Plant maintenace module. I want to change the PRTs associated to an operation (VORNR) of an Order (AUFNR) programatically. The PRT documents are created automatically in SAP with newer versions. Whenever a newer version is enco