?
Solved

java and mysql?

Posted on 2003-03-01
9
Medium Priority
?
218 Views
Last Modified: 2013-11-23
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)?
0
Comment
Question by:danBosh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 35

Expert Comment

by:TimYates
ID: 8047408
0
 

Author Comment

by:danBosh
ID: 8047421
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
 

Expert Comment

by:RayGun
ID: 8047598
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Expert Comment

by:anmasc
ID: 8047622
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
 

Author Comment

by:danBosh
ID: 8047954
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
 

Expert Comment

by:anmasc
ID: 8048033
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
 

Author Comment

by:danBosh
ID: 8048279
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
 

Expert Comment

by:anmasc
ID: 8051116
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
 

Accepted Solution

by:
RayGun earned 93 total points
ID: 8051973
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question