java and mysql?

I have java j2sdk1.4.1_01 and mysql-3.23.55.

1.What do I have to do to get these working together so that i can use jdbc.

2.Where do i get the java drivers from? which one(exact name and version)?
danBoshAsked:
Who is Participating?
 
RayGunConnect With a Mentor Commented:
After you have copied the .jar files into the correct path you need to configure your classpath as well if you are running a stand alone app. To do that go to start menu->run and type in the command I mentioned before.
Like this: java -classpath ./mysql-connector-java-3.1.0-alpha-bin.jar;.DbClient
Then run the application, it should work.

If you are running an applet you don't have to set up the classpath, but you still have to make sure that the java plug-in is pointing to the jre where your .jar file is located by opening the java plug-in admin program from the control panel. Under "advanced" you should be able to point the plug-in to the jre where your jar-files are located.


0
 
danBoshAuthor Commented:
I already downloaded http://www.mysql.com/downloads/api-jdbc-stable.html this but what do i do with is, it contains many files? Sorry for my ignorance but in the book i am reading i only have to specity one file in my code to link java and mysql, for example

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
RayGunCommented:
Your code should look something like this:
 
public void DbClient()
     {     username = new String("****");
          password = new String("****");

          databaseURL = new String("jdbc:mysql://server-2:1433;");
          databaseName = new String("server-2");

          //establish connection
          try
          {
               Class.forName("org.gjt.mm.mysql.Driver");

          }
          catch (ClassNotFoundException ex)
          {
               System.out.println(ex);
          };
          System.out.println("JDBC driver loaded");
          try
          {
               con = DriverManager.getConnection(databaseURL);//,username,password);
          }
          catch (java.sql.SQLException ex)
          {
               System.out.println("Error " + ex.getErrorCode() +ex.getMessage());
               //System.exit(0);

          };

Then you need to set up the classpath to the appropriate .jar files. Look around in your driver folder until you find a file with the .jar extension and then run this line in cmd to set up the classpath.
java -classpath ./<filename>.jar;.<App.name>

Good luck
0
 
anmascCommented:
Putt the jdbc driver (a .jar file) in this directory: javahomepath/jre/lib/ext/
then you can start the application width java <App.name> (not width the -classpath option)
0
 
danBoshAuthor Commented:
sorry....
so is this file org.gjt.mm.mysql.driver, in this zip here?i cannot find it? http://www.mysql.com/downloads/api-jdbc-stable.html. do i just unzip all these files to yjr jre/lib/ext directory?
0
 
anmascCommented:
Copy the zip file to jre/lib/ext/ and try it.

if it not runs then downolad the mysql-connector for java
http://www.mysql.com/products/connector-j/index.html (only 788kb)

anmasc
0
 
danBoshAuthor Commented:
I have copied the jar file into javahomepath/jre/lib/ext/ but when i write

class DbClient
{

   public static void main(String args[])
   {    
         try
         {
                   Class.forName("com.mysql.jdbc.Driver");
 
         }
         catch (ClassNotFoundException ex)
         {
              System.out.println(ex);
         }
     }
}

I get a class not found exception for: com.mysql.jdbc.Driver. This class is definatly in the jar file.
0
 
anmascCommented:
1.you only have to copy the jar file to javahomepath/jre/lib/ext/. The jar file is in the zip file (like this: mysql-connector-java-3.1.0-alpha.zip/mysql-connector-java-3.1.0-alpha/mysql-connector-java-3.1.0-alpha-bin.jar)
2.On my computer it runs! (Linux)

anmasc
0
All Courses

From novice to tech pro — start learning today.