wood burning stoves 2.0*
The moose likes JDBC and the fly likes connecting to online SQL DB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "connecting to online SQL DB" Watch "connecting to online SQL DB" New topic
Author

connecting to online SQL DB

swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
Hi people,

I have a .exe java application which require me to connect to online sql database. The database only have php scripting, no JDBC. Now my question is how am i going to connect? I read up and I need JApplet to be the bridge is this right?
Is there any help?

Thank you for reading, hope to see your reply soon =)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Welcome to the Ranch.

swee dx wrote:I have a .exe java application...

What do you mean with this; do you have a Java application which is compiled to a native Windows executable (*.exe file)?

swee dx wrote:The database only have php scripting, no JDBC.

You need a JDBC driver, which is normally only a JAR file that you have to put in your classpath. What kind of database is it (MySQL, Oracle, PostgreSQL, Microsoft SQL Server, ...)? For almost all kinds of databases there is a JDBC driver available, and you can usually find it on the website of the manufacturer of the database.

swee dx wrote:I read up and I need JApplet to be the bridge is this right?

A Java applet (that's what I guess you mean by "JApplet") is in itself not something that's going to help you connect to the database. You might need to make an applet, but maybe not, it depends on other things, like whether the database allows access from remote systems or not. An applet runs on the user's computer, inside the web browser. If the database can only be accessed from the server itself, you'll need Java code that runs on the server (for example, a servlet that you'd run in a Java EE web container or app server), not an applet that runs on the client.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38449
    
  23
Welcome to the Ranch

I am afraid we probably can't answer without knowing more details. But this sounds too difficult a question for "beginning Java", so I shall move it. Not sure where; let's try our databases forum.
swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
What do you mean with this; do you have a Java application which is compiled to a native Windows executable (*.exe file)?

No, sorry my fault it is a Executable JAR file

You need a JDBC driver, which is normally only a JAR file that you have to put in your classpath. What kind of database is it (MySQL, Oracle, PostgreSQL, Microsoft SQL Server, ...)? For almost all kinds of databases there is a JDBC driver available, and you can usually find it on the website of the manufacturer of the database.

Now i am using http://members.000webhost.com/login.php MySQL. They didn't provide JDBC driver for some unknown reason.

A Java applet (that's what I guess you mean by "JApplet") is in itself not something that's going to help you connect to the database. You might need to make an applet, but maybe not, it depends on other things, like whether the database allows access from remote systems or not. An applet runs on the user's computer, inside the web browser. If the database can only be accessed from the server itself, you'll need Java code that runs on the server (for example, a servlet that you'd run in a Java EE web container or app server), not an applet that runs on the client.


Yes, the database allows remote access. Meaning I have to upload the whole project into the server?? Im lost here. Sorry I'm new to web hosting.

Thanks to Campbell Ritchie, ya I'm not sure where i should post. Thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38449
    
  23
Surely MySQL provide a JDBC driver? Like Java™, MySQL is provided by Oracle.
swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
=( no unfortunately, campbell. I went to a couple online MySQL database hosting service they mention JDBC and executable JAR file program are not able to connect with them, even with paid hosting.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
Having applets connect via JDBC from the open internet is not a good idea for security reasons; I can understand hosting companies preventing that.

A server-side HTTP proxy -like Jesper mentioned- (in your case implemented in PHP) would be a way around that.


Ping & DNS - my free Android networking tools app
swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
Thanks Ulf for reply, but i serious have no idea and i google the problem. How can Java integrate/communicate with php?? Please help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
Via HTTP. The applet would send HTTP requests to the PHP page that contain all the parameters the PHP page would need to make a DB call. The PHP page would then read the DB's response, and reformat them in some way that's suitable for the applet to consume (maybe JSON or XML).

Here's code that does part of what the applet would do: http://www.exampledepot.com/egs/java.net/ReadFromURL.html
swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
thanks ulf.
can it implement in Java file not Java Applet because i try to link my java application to Java Applet but failed.

so the php just have the functions to retrieve data right? my php is upload to the server. I really have been trying to solve and learn php.

Thanks for all the help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
can it implement in Java file not Java Applet because i try to link my java application to Java Applet but failed.

I'm not sure what you're asking here. A "Java application" is generally understood to be a desktop application - that's different from an applet. If you want to run your code as an applet, then you'll have to rewrite it to *be* an applet.

But it's perfectly possible for the code I pointed to to be part of a desktop application. Depends on whether you want a desktop app or an applet; an applet is certainly not required to connect to a server.
swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
Thank you so much Ulf

Sorry about my terms. Yes mine is a Java application, desktop application. I try to program my Java application to call/execute the java applet but fail.

It can't be convert to java applet because of file chooser not available in java applet [security reason] and java.awt.geom* which allow user to draw different shapes.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
Yes mine is a Java application, desktop application. I try to program my Java application to call/execute the java applet but fail.

I don't know how you tried to "call/execute" an applet from a desktop application (something that seems to make little sense), but as I said, there's no need to use an applet as far as I can tell from your previous posts. Maybe you can elaborate on why you think you need to use one?
swee Ryan
Greenhorn

Joined: Jan 20, 2011
Posts: 7
thank you for your help and patient.

As i Google, i bookmark a couple of them showing how Java applet integrate with java applet. I try google for java application to integrate with php also but it is not i wanted. thus i thought maybe java application link to java applet so that it can link with my online sql database.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41592
    
  55
how Java applet integrate with java applet.

Sorry, I have idea what you mean by "integrate an applet with an applet".

java application to integrate with php also but it is not i wanted.

I wouldn't call an HTTP call "integration"; it sounds like you may have found something unrelated.

thus i thought maybe java application link to java applet so that it can link with my online sql database.

Again: A Java desktop application has no problems making HTTP calls to a web server, whether implemented in PHP or some other technology. An applet is not required for this. Have you tried the code I linked to earlier? If not, that would be a good start.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connecting to online SQL DB