Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (517)
Games in Android Showcase (123)
games submitted by our members
Games in WIP (578)
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 1554 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();
BURI = BURL.toURI();
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();
//DriverManager.registerDriver(null);
Connection C=null;
C=DriverManager.getConnection("jdbc:mysql://myserver.com/mydb",un,pw);

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
Online ra4king

JGO Kernel


Medals: 353
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....


Huh
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: http://code.mattcampbell.net/espresso-mysql/file/tip/mysql.js
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.

https://play.google.com/store/apps/details?id=com.bullsquared.alggame Annoying Little Gits (Android)
www.bullsquared.com   Play java (applet) games! www.chessclockpro.com Free Online Chess Clock
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 Wizard


Medals: 86
Projects: 1
Exp: 6 years


Java guru wanabee


« 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

Mike

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.

https://play.google.com/store/apps/details?id=com.bullsquared.alggame Annoying Little Gits (Android)
www.bullsquared.com   Play java (applet) games! www.chessclockpro.com Free Online Chess Clock
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.
 Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

DarkCart (6 views)
2014-10-31 21:44:48

DarkCart (7 views)
2014-10-31 21:43:57

TehJavaDev (38 views)
2014-10-27 03:28:38

TehJavaDev (29 views)
2014-10-27 03:27:51

DarkCart (43 views)
2014-10-26 19:37:11

Luminem (24 views)
2014-10-26 10:17:50

Luminem (29 views)
2014-10-26 10:14:04

theagentd (35 views)
2014-10-25 15:46:29

Longarmx (63 views)
2014-10-17 03:59:02

Norakomi (61 views)
2014-10-16 15:22:06
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!