
|
View Full Version : Java / Php & MySQL?
PHaWKs 10-24-2006, 05:28 PM Hi,
I want to have an application with a web interface and a gui, both running from the same database. Is java compatable with a mysql database if so how?
Thanks.
Mark S 10-24-2006, 05:47 PM Yes, I have a basic foundation in Java; you can via importing the appropriate things (i.e. import java.sql.Connection).
Google is your friend: http://www.google.com/search?q=Java+MySQL
spryandrew 10-24-2006, 07:18 PM Java uses the Java Database Connectivity (JDBC) API as its primary method for connecting to daabases. And yes, the JDBC will let you connect to MySQL, or most any other SQL based database system.
cornerhost 10-25-2006, 01:08 PM Hi,
I want to have an application with a web interface and a gui, both running from the same database. Is java compatable with a mysql database if so how?
Thanks.
You can use Java to talk directly to the database with jdbc. But, you might not actually want to do this.
The first question is, who has access to the GUI? If this is all inside your company on an intranet, having java talk directly to the database is probably okay. But if the GUI is going to be available to the public, you'd have to open your database to the world, and that could be dangerous. (Also, many people would have firewall issues trying to talk to the MySQL port)
The other problem is having duplicate code between the php and java versions.
You might find that a better approach is to write the web app, and then create a SOAP or XML-RPC API so that the web server handles all the logic, and the GUI clients can just make it look nice.
The other thing to think about is: would it make more sense to write both sides in Java? Even with a web service, you might be reusing various classes in the two versions, and if they're both written in java you can reuse the code directly.
<<Signature to be setup in your profile>>
As already mentioned you need MySQL's Connector library (http://dev.mysql.com/usingmysql/java/).
I am programming a webapp in Java as well. One of the hottest technologies now are Object Relation Mappers (ORM). Basically you can avoid having to code SQL and instead work with objects directly. They get populated with data from the database automatically, and any changes you make to the object will propagate back in. You can find more information by looking it up on wikipedia or google. The most popular ORM for java is probably Hibernate. It can save you a lot of time and you don't need a DBA right away. Good luck!
mwatkins 10-25-2006, 05:33 PM Mr. Wallace's comments hit the right chords. If your application - GUI clients and web "clients" - are all on a network that you or your client controls (private or proven to be secure) then exposing SQL across the wire to GUI clients (via whatever DB glue you choose to use) is a timed honoured technique.
If on the other hand you need to support GUI clients outside of a controlled network, you might want to consider XMLRPC, SOAP, or perhaps preferably, REST for opening up your core API to remote GUI clients. Sure you can open up a public port to a database server, but you probably really don't want to do that.
I like Michal's thoughts on writing both aspects of the application in one technology. Here's where PHP is less useful than say Java or Python. Either Java or Python can be used to create cross-platform GUI applications. The two take different approaches to this end.
You'd save a lot of time, and future maintenance, by consolidating your core application libraries and APIs on one language platform. You'll write the core logic only once (and thus have only one "core" to maintain) and then two clients - one gui, one web.
xelav 10-28-2006, 10:53 AM If it's GUI for simple application, you can use XML for database exchange. I was working for similar project, where had java client for managing store. Now thinking about similar on .NET.
BTW, there are ORM for php too.
2mwatkins: I think, he has written php/mysql application, and need a gui manager solution on java
mwatkins 10-28-2006, 11:52 AM 2mwatkins: I think, he has written php/mysql application, and need a gui manager solution on java
Could be; problem is the OP's question is vague on the point and the OP has posted and run (like "cut and run").
ntkennedy 10-28-2006, 06:26 PM You aren't too clear on your design criteria, so I don't know if Java is a good choice for your application. Obvious Java, and every other real programming language, supports MySQL. But how is your app being deployed? Is it on one box or distributed? Are both GUi and web clients running over the network?
|