473,385 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Mac leapord. NetBeans. Mysql and class path

65
Hi All,

The code at the bottom of this message is an example (1 of 3 i have tried) of trying to connect to a localhost mysql database.

It wont, and the exception displayed is the one i have set.

Im fairly convinced its something to do with the driver not being installed.

I have downloaded it and unzipped it and installed it, and got the green success tick.

But it still will not connect.

How do i set a class path?
My only other option is to dual boot windows, which i really dont want to do.

Expand|Select|Wrap|Line Numbers
  1. import java.sql.*;
  2.  
  3.    public class Connect
  4.    {
  5.        public static void main (String[] args)
  6.        {
  7.            Connection conn = null;
  8.  
  9.            try
  10.            {
  11.                String userName = "root";
  12.                String password = "root";
  13.                String url = "jdbc:mysql://localhost:3306/test/";
  14.                Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  15.                conn = DriverManager.getConnection (url, userName, password);
  16.                System.out.println ("Database connection established");
  17.            }
  18.            catch (Exception e)
  19.            {
  20.                System.err.println ("Cannot connect to database server");
  21.            }
  22.            finally
  23.            {
  24.                if (conn != null)
  25.                {
  26.                    try
  27.                    {
  28.                        conn.close ();
  29.                        System.out.println ("Database connection terminated");
  30.                    }
  31.                    catch (Exception e) { /* ignore close errors */ }
  32.                }
  33.            }
  34.        }
  35.    }
  36.  
  37.  
Oct 27 '09 #1
2 3101
whitep8
65
good evening all,

I finally managed to get this script to work.

I had to javac it with the driver in the same directory and it worked fine.

That leads onto my question, how can i avoid that and get it to run in netbeans?
Oct 28 '09 #2
Dököll
2,364 Expert 2GB
Thanks for letting us know that it worked and what you did to arrive at that conclusion, get a load of this link:

http://bytes.com/topic/java/answers/...op-apllication

Also, fire Google, type in "Netbeans Video Tutorials for Web Applications" and get yourself some coffee call it a night.

You should come out happy:-)
Nov 10 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
3
by: Joseph Jolic | last post by:
Hi i just installed Netbeans on my windows pc and it installed fine. but when i try to run it i get: JDK 1.3 or later cannot be found on your machine. Please read the README file. i read...
0
by: Huub | last post by:
Hi, Can somebody tell me if MySQL Connector/J 3.0 works ok with NetBeans? Just installed Connector/J but when running the intended Java-application from NetBeans it tells me this: > Connected...
0
by: Federico | last post by:
Hi all, I don't know if this topic is perhaps a little bit off-topic, anyway I have a strange problem in transforming an XML file in an HTML file using XSLT form a Java program written with...
4
by: jsiii | last post by:
Hello, I am trying to develop JSP application with Visual Web Pack in Netbeans 5.5. I am trying to connect to MySql database. It was going all well and with some minor problems I was able to...
0
by: hInCh | last post by:
hi, i am having problem,configuring netbeans (tomcat 5.5) with mysql j/connector. i ve used datasources,and getting the error message like. Error Code=0 SQL State=null Cannot load JDBC...
3
by: arasub | last post by:
ep 20, 2007 11:25:57 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found...
2
by: rathnaravi | last post by:
I am using NetBeans 5.0.I tried to connect MySQL with Crystal Reports XI.When writing the coding in Java Application.I get the following error....
2
myusernotyours
by: myusernotyours | last post by:
Hi All, Am working on a Java application in which I have to use the JNI to Interface with some native code for both windows and unix. Am using netbeans IDE with the C/C++ pack installed. Am also...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.