Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  loading mysql connector jar  (Read 3158 times)
0 Members and 1 Guest are viewing this topic.
Offline stegzzz

Senior Newbie

« Posted 2011-07-29 16:47:42 »

Hi, I'm trying to load the mysql connector jar file "on-the-fly" but getting a "no suitable driver" message when I try to get the connection.

I've got an applet sitting on my server along with the mysql jar file and when I run the applet from a web page with the jar named as an archive it all works fine. But, to shorten the load time I want to load the mysql jar later in the program while the user is paused reading some instructions. So here's the code:

URL BURL=getCodeBase();
URLClassLoader cl = null;
cl = new URLClassLoader(new URL[] {BURI.resolve("mysql-connector-java-5.1.14-bin.jar").toURL()});
Class.forName("com.mysql.jdbc.Driver", true, cl);
//Class.forName("com.mysql.jdbc.Driver", true, cl).newInsance();
Connection C=null;

The comment lines are among variations I've tried but I keep ending with the same problem when getConnection is called "no suitable driver found".

Any ideas?

Thanks, Steve
Offline ra4king

JGO Kernel

Medals: 508
Projects: 3
Exp: 5 years

I'm the King!

« Reply #1 - Posted 2011-07-29 16:56:53 »

Does "BURI.resolve("mysql-connector-java-5.1.14-bin.jar").toURL()" return the correct URL? Try making sure it does.

Offline stegzzz

Senior Newbie

« Reply #2 - Posted 2011-07-29 19:12:19 »

Hi, yes BURI.resolve("mysql-connector-java-5.1.14-bin.jar").toURL() does seem to return the correct name. And applying getName() to
Class.forName("com.mysql.jdbc.Driver", true, cl) results in com.mysql.jdbc.Driver which I took to indicate the driver was loaded correctly by forName().

But, still get the error....

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline woogley
« Reply #3 - Posted 2011-07-29 21:18:30 »

I ran into this while writing a web application server with JS/Rhino. I wanted to allow applications to load it at runtime if they need to without having to bundle it with the server itself.

I can't remember the details, but for some reason, mysql connector doesn't register itself as a candidate for DriverManager. The solution I used was to call connect() on the driver instance directly.

You can see my code for this here:
Offline steveyO
« Reply #4 - Posted 2011-07-30 19:32:43 »

Just out of interest, why do you have the MySQL .jar on the client, sounds extremely risky.  2D Game Editor + Random Graphics Generator
Offline stegzzz

Senior Newbie

« Reply #5 - Posted 2011-07-30 20:31:16 »

Thanks Woogley, I'm connected Smiley
Offline stegzzz

Senior Newbie

« Reply #6 - Posted 2011-07-30 20:34:41 »

SteveyO erm, no intention to introduce a security risk, just to optimise the downloading so it can take place at a convenient time in the game rather than cause delays on startup if loaded via the html applet archive tag.

How does the what I'm doing differ and make a security risk?
Offline Mike

« JGO Spiffy Duke »

Medals: 149
Projects: 1
Exp: 6 years

Java guru wannabe

« Reply #7 - Posted 2011-07-30 20:42:03 »

It has more to do with the fact that if you connect to the mysql database directly from the applet (loaded directly or later) everyone will be able to see your mysql username and password. Just make sure you limit the access of the user so he only can select, and that everyone is allowed to see all data that is in the tables where the user has the privilige to select. That should be fine as long as no one comes around and floods your database with requests, but there are many ways to do that Smiley


My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline steveyO
« Reply #8 - Posted 2011-07-31 08:43:13 »

The security risks are pretty much described as Mickelukas.  I would of thought a better way to do this is to send your db updates via a URLConnection (e.g. in xml/json/string format) and do your db updates on the server side.  This way you solve your problem of download size (no need for client mysql jar) and don't expose your database to the world.  2D Game Editor + Random Graphics Generator
Offline stegzzz

Senior Newbie

« Reply #9 - Posted 2011-07-31 14:29:11 »

Ah, OK, I see what you mean SteveyO and Mickelukas. I'll look into URLConnection.

Chrs, Steve.
Pages: [1]
  ignore  |  Print  

DesertCoockie (20 views)
2018-05-13 18:23:11

nelsongames (68 views)
2018-04-24 18:15:36

nelsongames (65 views)
2018-04-24 18:14:32

ivj94 (748 views)
2018-03-24 14:47:39

ivj94 (79 views)
2018-03-24 14:46:31

ivj94 (579 views)
2018-03-24 14:43:53

Solater (95 views)
2018-03-17 05:04:08

nelsongames (168 views)
2018-03-05 17:56:34

Gornova (362 views)
2018-03-02 22:15:33

buddyBro (1022 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!