J2EE project has connection problem to mysql

I have an urgent problem. I accidently deleted my Java installation. Not a major problem or so I thought. This also included my tomcat install and eclipse install.

So I began the process of the reinstalling. The problem here though is that when I loaded an application I was working on at work. It wont allow me to connect to the MySQL database. This is a serious problem. What happened or changed that could have cause this. Would a new version to Tomcat/Java/J2EE/Eclipse be causing this problem?

Please help
bhessionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
Post what kind of error you see.
0
bhessionAuthor Commented:
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/myapp
0
bhessionAuthor Commented:
This is very frustrating as I have nothing changed
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

for_yanCommented:
Still you obviouslky have to check if you have the appropiate .jkar with mysql driver - believe it is named something like ConnectJ - easily can be found accessible to your web application - say in WEB-INF/lib
0
bhessionAuthor Commented:
its in there and its in the build path. So there is no reason why it shouldnt work
0
for_yanCommented:
This is strange.

Check the name of the class of the driver - if it is in the jar file the way you call it in the code.
Myabe you previously had some older version in the code and now it changed the name
and now you have newer version jar.

You can alos put it into general lib under tomcat home folder
0
for_yanCommented:
do you have the driver class name explicitly in the code, or you set up some parameters thriugh tomcat (like in xml,etc.)  
0
bhessionAuthor Commented:
What you mean with the below?
Check the name of the class of the driver - if it is in the jar file the way you call it in the code.

Also how do you do this?
You can alos put it into general lib under tomcat home folder

Here is my connect code

Connection con = null;
	Statement stmt = null;
	PreparedStatement ps = null;
	ResultSet rs = null;
	String dbURL = "jdbc:mysql://localhost:3306/myapp";
	String username = "username";
	String password = "password";
	
public void Connect1()
	{
		try
		{
			con = DriverManager.getConnection(dbURL, username, password);
		}
		 catch (Exception e) {
			 System.out.println(e);
				System.out
						.println("An error has occurred during the connection phase! Did you upload your Oracle Drivers?");
			}
		}

Open in new window

0
for_yanCommented:

No, you need to either setup it with connection pool aet up in Tomcat, or you need to have it in the code
either with explicit import startements or in
Class.forName(....) statement which should be called before DriverManager

On the other hand this class name/path which is refrreed in the connection pooling setup of in Class.forname() statement
should be present in the jar
To check that you copy the .jar to the file ending with .zip and open it with Winzip or any other windows
zipping program and check, say if you have

 Class.forName ("oracle.jdbc.driver.OracleDriver")

then in your jar you would need to have class

oracle/jdbc/driver/OracleDriver.class

I of course used oracle as a handy example

For my SQL you 'd have different path and class name of course

 




0
bhessionAuthor Commented:
This was the line or at least the mysql equiv, strange it worked with my earlier installation for months, suddenly a problem with my new installation. Truely baffling. Thank you so much for your help!

 Class.forName ("oracle.jdbc.driver.OracleDriver")
0
for_yanCommented:

That is how I was recently connecting to MySQL with driver class name

com.mysql.jdbc.Driver

jar name is :
mysql-connector-java-5.1.15-bin.jar

 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.Statement;
 
 public class TestMySql {
 
      public static void main(String[] args) {
   System.out.println("MySQL Connect Example.");
   Connection conn = null;
   String url = "jdbc:mysql://server_name:3306/";
   String dbName = "dbname";
   String driver = "com.mysql.jdbc.Driver";
   String userName = "user";
   String password = "password";
   try {
   Class.forName(driver).newInstance();
   conn = DriverManager.getConnection(url+dbName,userName,password);
       Statement stmt = conn.createStatement();
       ResultSet rs = stmt.executeQuery("select * from java_mysql.test_table");
       while(rs.next()){
           String s = rs.getString("a");
           float f = rs.getFloat("b");
           System.out.println("a: " + s + " b: " + f);
        
       }
 
 
   System.out.println("Connected to the database");
   conn.close();
   System.out.println("Disconnected from database");
   } catch (Exception e) {
   e.printStackTrace();
   }
   }
 
     
 }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bhessionAuthor Commented:
Excellent diagnosis. Thanks again
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.