but how do you "connect" the application to the database?? I need some help big time... i looked at the sun tutorial, but that drivermanager and driver stuff isnt very clear when you try to use generic names.
It looks confusing because there is a separation between the driver and connection when first connecting to a database. This ends up being very useful in the long run since it helps write code which is independent of the database, but that doesn't help the initial confusion.
To connect to a database (in general) you need these things:
1) The fully qualified class name of the Driver class 2) The Database URL - more in a minute 3) The DB username and password.
I haven't put the specific strings into the last part, as it is exactly the same for every DB once you have parts 1, 2 and 3.
I mentioned a separation above, and this is where the DB URL ends up telling the DriverManager which Driver to use to get a Connection. If you go straight to the specific Driver then your code becomes coupled to a Database. If you keep them as Strings - and use the correct values - then they find each other and you can easily move the Strings to a Properties file and suddenly you can change to almost any DB. I theory, anyway.
ok so the driver_name is com.mysql.jdbc.Driver (or the other one) right?
and for the DB_URL, thats the jdbc:mysql://localhost:3306/myDatabase right? and if this is right, can i create a DB_URL object that points to "jdbc:mysql://localhost:3306/myDatabase"? and if so would it be like this:
URL DB_URL = new URL("jdbc:mysql://localhost:3306/myDatabase",localhost); something along those lines, cant remember if the host come first or last.
but for the name and password, do you set that up with the dbms?
i added .newInstance() to the class.forname thing.
I downloaded the driver "org.gjt.mm.mysql.Driver" but i dont know how to put the -jar file or the folder containing /org and all of its components in my classpath... is the classpath the same as path? if so, its not working..
You may want to try something like the following: private final String DBCONNECT = "jdbc:mysql://localhost/database_name?user=db_user&password=db_password"; (I have a simple utility class that I wrote, and this is how I do it)
Where database_name is the name of the database to which you are trying to connect, db_user is the user that you created, and db_pass is the password.
Your application shouldn't care where the database is. It really doesn't need to. It just hits the port on which Mysql is running. Did you change the default port? [ August 12, 2007: Message edited by: Chad Clites ]