We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOther Libraries › can't connect to MySQL
Page Index Toggle Pages: 1
can't connect to MySQL (Read 2631 times)
can't connect to MySQL
Apr 25th, 2009, 9:44pm
 
Hi all
trying to use the SQL lib to connect to a database with no luck. I have one local and live to test with. Does this only work with server side apps embedded in a web page. If so, do any extra steps need to be taken to sign the exported applet or similar to have it connect?

All I am doing at the moment is modifying the 2 mysql examples. When running in the IDE with my local database i get
Code:

SQL.connect(): Could not connect to the database ( jdbc:mysql://localhost/abc_visualisations ).

com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:

** BEGIN NESTED EXCEPTION **

java.net.SocketException
MESSAGE: java.net.ConnectException: Connection refused


and when i try my live database on dreamhost i get:

Code:

SQL.connect(): Could not connect to the database ( jdbc:mysql://mysql.serialspace.org/abc_visualisations ).

java.sql.SQLException: Access denied for user 'infostudio'@'124-170-88-183.dyn.iinet.net.au' (using password: YES)


When running on my local server in browser it doesn't connect either.

I am running the most current OSX, Processing and SQLibrary.
Any help greatly appreciated. Note that I had to manually copy the lib files into the code folder to get this far as Processing didn't automatically copy the dependencies for the SQL lib over.
Re: can't connect to MySQL
Reply #1 - Apr 25th, 2009, 11:09pm
 
"server side apps embedded in a web page"
applets (anything inside a web page) are run in your browser not on the server.

you should not use sql library for applets, better have a php script on the server talk to the database and deliver the results to the applet.

about your connection problems: the second one is just saying that you can't connect to your remote database with that user. could be several things: either the user/pass is wrong or your user is not allowed to connect from a remote location (other than localhost i.e.).

the first error is hard to debug ... it says that your database refuses the connection. i assume you can connect to the database locally (terminal / phpMyAdmin/ else)?

why did you copy the files into the code folder? the library should work fine as it comes ...

F
Re: can't connect to MySQL
Reply #2 - Apr 26th, 2009, 2:17am
 
fjen wrote on Apr 25th, 2009, 11:09pm:
you should not use sql library for applets, better have a php script on the server talk to the database and deliver the results to the applet.

Already explained elsewhere in the forum, but better to repeat why:
- There might be problems of signing (eg. if applet is hosted on a different server than where the database is);
- There is a security issue: in general ID and password are hard-coded in clear in the applet, and one can easily get the jar, extract the .class and transform it to .java to see the confidential information, then hack the database!
Re: can't connect to MySQL
Reply #3 - Apr 26th, 2009, 5:24am
 
Thanks for the quick replies guys,

I don't wish to use an applet, was just wondering if I had to as I forgot they weren't server side and was having connection issues.

For the live server, I was able to add remote hosts via the hosts web panel. Unfortunately I was hoping to have some students do this for a class project so may have to use an alternative, rather than adding 30+ IPs to the web panel!

For my local MAMP server, I realised I just forgot to specify the port:
"localhost:8889"

The reason I copied the files to the code folder was that Processing only copied the one file and not the dependencies on first run and then complained about a dependency missing until I manually copied the rest into the folder.

and apologies for not finding this in the forum - just realised I was only searching posts a week old!

thanks again,
nay.
Re: can't connect to MySQL
Reply #4 - Apr 26th, 2009, 2:32pm
 
nay wrote on Apr 26th, 2009, 5:24am:
The reason I copied the files to the code folder was that Processing only copied the one file and not the dependencies on first run and then complained about a dependency missing until I manually copied the rest into the folder.


? what did you do there the contents of the zip that you downloaded has to go into the libraries folder. Processing should not copy anything here ... did you drop the files in the window

sorry, wrote zip, ment to write contents of zip ...

libraries/
--SQLibrary/
----documentation/
----examples/
----library/

F
Re: can't connect to MySQL
Reply #5 - Apr 27th, 2009, 2:07am
 
thats what i did. then on first run p5 created a code folder in my sketch folder and copied one lib file into it and gave me a dependency error. when i copied the rest of the files from
sketch/libraries/SQLibray/library/
into the code folder and tried again it worked.
Re: can't connect to MySQL
Reply #6 - Dec 4th, 2009, 1:12pm
 
Regarding the error message that you were getting, I was also having a similar problem with my WAMP UniServer installation:

Quote:
SQL.connect(): Could not connect to the database ( jdbc:mysql://localhost:3306/apologygrovelocal ).

java.sql.SQLException: Unknown initial character set index '192' received from server. Initial client character set can be forced via the 'characterEncoding' property.


I finally fixed it not by specifying the port number in the SQL server but by specifying the character encoding. Florian Jenett's example actually has it in his example, but commented out:

String database = "bildwelt";
// add additional parameters like this:
// bildwelt?useUnicode=true&characterEncoding=UTF-8
Page Index Toggle Pages: 1