Results 1 to 5 of 5
- 02-21-2011, 05:47 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Applet connection to MySQL database using JDBC
Hi,
For coursework at school I am using java to create a system which uses a database to store information and a java applet to display and insert from and into the database.
I have been developing the program with the database and applet both running on the same computer, but in reality the database is server side and the applet is client side.
When i attempt to connect to the database on another server, i am unable to make a connection, although i do change the address from localhost to the domain on which the database is hosted.
Here is the code:
Annnnd this is the error I get, which would be expeced:Java Code:public static void setupConnection() { try { Class.forName("com.mysql.jdbc.Driver").newInstance(); con = DriverManager.getConnection("jdbc:mysql://thenicestthing.co.uk/music?user=username&password=******"); }catch(Exception e){ e.printStackTrace(); } }
com.mysql.jdbc.exceptions.jdbc4.CommunicationsExce ption: Communications link failure
Some help would be brilliant!Java Code:The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)... etc.
- 02-21-2011, 10:08 PM #2
yea, This keeps coming up. where applets trying to make JDBC database connections don't work in general. I should write a post or a top level FAQ for this or something.
Mainly because JDBC is a server side technology. Where applets may only always and forever communicate with the HTTP server of which they originated from (same server as their codebase). and in general the database will almost always be on a different server.
So, we need some kind of web service or custom query mechanism, eg. XML RPC over HTTP, or JSON over HTTP, perhaps RMI, but likely something over HTTP is better.
where we have the APPLET invoke HTTP requests to a Servlet in the server of which receives these requests (also handles authentication, authrorization) and then uses a JDBC connection to the database to invoke some query, unpack the result set into the HTTP servlet response in a suitable format (e.g XML, JSON, etc, what ever was used for request and what ever the applet is expecting as a response).
Which means you'd need a webapp at least with a servlet listening on a url that your applet is able to invoke, and have the database JDBC connection available to this servlet.
- 02-22-2011, 12:34 AM #3
Member
- Join Date
- Feb 2011
- Posts
- 2
- Rep Power
- 0
Thanks a lot for the reply.
I was thinking of using a php script to simply deal with SQL queries, and then request the page and read the output as a string, as I'm not at all confident in writing jsp, especially with a problem as complex as this, I'm doing my computer science degree next year, I'm pretty amateur at the moment!
My current code makes use of result sets, would there be a way of creating a result set from the php page output?
- 02-22-2011, 03:31 AM #4
maybe render some simple xml-like output to model rows and columns.
Java Code:<resultset> <r> <c name="mycolumn1">some value</c> <c>bla bla</c> <c> </r> . . . </resultset>
- 02-25-2011, 04:33 AM #5
Member
- Join Date
- Nov 2009
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
JDBC.ODBC Error : Microsoft Access Database not connection
By nizghat in forum New To JavaReplies: 0Last Post: 02-16-2011, 01:30 PM -
JDBC and mySQL database trouble
By ichwar in forum JDBCReplies: 17Last Post: 08-16-2010, 11:21 PM -
JDBC DataBase Connection
By sh4dyPT in forum New To JavaReplies: 1Last Post: 04-06-2010, 02:13 AM -
JDBC problem with multiple resultsets on mysql database: getUpdateCount() always zero
By plica10 in forum JDBCReplies: 3Last Post: 02-02-2010, 01:33 PM -
[SOLVED] applet connection to mysql db on home server
By shwein in forum Java AppletsReplies: 1Last Post: 10-29-2008, 05:38 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks