aspose file tools*
The moose likes JDBC and the fly likes I need to get pointed in the right direction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "I need to get pointed in the right direction" Watch "I need to get pointed in the right direction" New topic
Author

I need to get pointed in the right direction

Vidya Ishaya
Greenhorn

Joined: Apr 08, 2011
Posts: 4
I am an experienced PHP programmer who uses PHP with MySQL.

I am learning Java and would like to write some Java stand-alone
programs (to run on my desktop) that can access a MySQL database
that I have on a webhost.

I don't know where to go to find instructions on how to access a
MySQL database, and how to send SQL instructions, etc.

The second thing is I'd like to write stand-alone Java that can have a GUI
where part (or all) of the GUI is a panel in a frame that is displaying the
contents of a website page. Thus, I can be runnning a stand-alone program
that looks like a regular running program in one part, and in another part
(or maybe the whole part) is actually coming from PHP programs on a webpage.

If you can point me in the right direction so that I can learn how
to do these things, I'd be most grateful.

...Burton Smith
www.webwisesage.com
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

You can connect to a database using JDBC.

There are no standard components that have the functionality that you need. Maybe there is a library that does.


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

There are two possibilities for connecting to your database:

1) The MySQL database is publicly accessible. You can use regular JDBC to connect to it. I wouldn't count on it though, as this is a rarity.

2) The MySQL database is only accessible from the web server itself. That means you can't use regular JDBC to connect. You will need to create a layer between the database and the application on the web server. Your web server will behave like a (sort of) web service. You do an HTTP POST or GET to a (PHP) page you created that does the work for you. That page then gives you back the results. I suggest using XML as the MIME type of the generated pages. Also, restrict these pages to not accept any query, because that will create a huge security leak.

In short: create a page for each query you want to perform. Parameters to the queries are not a problem, but do remember to add proper validation in your PHP pages. For example: a GET request to http://yoursite/get_product.php?id=5 would return an XML document with the data of the product with ID 5.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
I think this thread would sit better on another forum. Let's try the databases forum first.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I need to get pointed in the right direction