1

I'm trying to make connection from flex to java and from java to mysql. I managed to connect to java, but having error that class not found: com.mysql.jdbc.Driver. But I downloaded mysql.jar, included it added to library, and connection works when I testing it from eclipse scrapbook. Don't know what to do.

Class.forName("com.mysql.jdbc.Driver");
String username = "username";
String password = "password";
String database = "database"
String url = "jdbc:mysql://localhost/" + database;
connect = DriverManager.getConnection(url, username, password);
statement = connect.createStatement();
resultSet = statement.executeQuery(query);

SOLVED

Basically the solution was simple. Everybody keeps saying to put jar into lib folder, so I done it, but I wasn't realised that I have to put into my servers lib directory, not app lib directory and this miserable mistake cost so much.

In this particular situation I'm using red5, so I putted it into my red5 dist/lib directory and "surprisingly" it's started to work.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Giedrius
  • 1,590
  • 3
  • 16
  • 27
  • no i only try with jdbc. isnt ojdbc for oracle? I forgot to mention that im very new at the java and flex, i been working with php before. Can you give more details about ojdbc? – Giedrius Sep 13 '11 at 23:25
  • I'm sorry, I didn't note mysql. Update the first line of the code to Class.forName ("com.mysql.jdbc.Driver").newInstance (); and give it a try! – kbgn Sep 14 '11 at 00:39
  • @kbgn: this is a myth and wild guessing. The extra `newInstance()` call is only necessary for the buggy `org.gjt.mm.mysql.Driver`. See also http://stackoverflow.com/questions/5992126/loading-jdbc-driver Also, the `ClassNotFoundException` is thrown on `forName()` call, so the `newInstance()` wouldn't ever be called and can therefore never "fix" it. – BalusC Sep 14 '11 at 00:51
  • Giedrius, the exception is telling that the JAR file isn't in the runtime classpath of your Java application. I have however no utter idea how Flex and Java communicate with each other, so I can't give a suitable answer. At least it boils down to that you need to put the JAR file in the runtime classpath, or to add the path to the JAR file to the runtime classpath. How to do it depends on how you're executing your Java application. Is your Java application basically a `.class` file or a `.jar` file? How exactly do you execute it? – BalusC Sep 14 '11 at 00:56
  • @Giedrius, If you've solved your problem, then please add it as an answer and accept it so the community knows it's solved. – jswolf19 Sep 14 '11 at 03:55
  • @jswolf19, ill do it, just have to wait now for tomorrow. im not allowed to do it now. – Giedrius Sep 14 '11 at 12:03

1 Answers1

1

Basically the solution was simple. Everybody kept saying to put jar into lib folder, so that is what I did, but I didn't realise that I that I needed to put it into my servers lib directory, not the app lib directory and this miserable mistake cost so much. Anyway I hope this will help for some newbie like me.

In this particular situation im using red5, so I put it into my red5 dist/lib directory and "surprisingly" its started to work.

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
Giedrius
  • 1,590
  • 3
  • 16
  • 27