aspose file tools*
The moose likes JDBC and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark ""porting" a PHP application to Java..." Watch ""porting" a PHP application to Java..." New topic
Author

"porting" a PHP application to Java...

J Sellers
Greenhorn

Joined: Mar 06, 2009
Posts: 10
I have a couple of questions that span across categories so I hope this is the right place to post this question, especially since I am a Java newbie. I'll start by saying that I am pretty new to Java having only completed an "introduction to Java" type class and am currently working my way through "Headfirst Java".

The best way for me to learn is to actually create something I want or am interested in, so for my first real project I'm trying to re-write a PHP front end application I created. Since it is the front end, all it really does is pull data from a MySQL database and display it to the user via web pages. Of course it's a bit more complex then that, but that is the high level overview.
My problem is that during my research on how to do this in Java I am getting all sorts of information that I can't really digest. Topics such as Hibernate, the Spring framework, EJB's and all other sorts of stuff start cropping up and I end up getting a bit overwhelmed with all the terms and technology. I know that this new application will need to be a servlet so I've been researching that, but outside of that I am kind of lost.

With my PHP application I use a database abstraction layer that creates a persistent connection in one .php file (the main config file). This connection is a global variable that is accessed via all the other db methods, so I can basically reference it from wherever. One thing that I am trying to wrap my head around is how I do this with Java since everything is an object? Most of the stuff I've read says to keep most of your stuff out of main() and in separate classes. My initial thought was to create a class that handled all the database stuff (connection, query, inserts, etc) but then each time I want to do something with the database I need to create a new database connection (object). That seems like it could be very messy and resource intensive. I have found a few code examples of interacting with a database, but they are all pretty basic and most of the code is run in main(). So the program works well but it only runs once and that is it.

Sorry for the rambling, I'm just looking for maybe some pointers on how to get this started and what libraries, framework(s), tools (if any) I really need to get this started. I have ordered the Headfirst Servlets & JSP book as well to help me along in this process.

TIA
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36566
    
  16
Welcome to JavaRanch

I would suggest you try sorting out your database connectivity first. I presume you have your database already set up? The Java Tutorials contains a section about database connections; have a look at that. It tells you about connecting. The MySQL manual has details about connecting; I think it is section 19. Look where it says "Java."

Do the project in little bits, and make sure each bit works before trying the next bit.
J Sellers
Greenhorn

Joined: Mar 06, 2009
Posts: 10
Campbell Ritchie wrote:Welcome to JavaRanch

I would suggest you try sorting out your database connectivity first. I presume you have your database already set up? The Java Tutorials contains a section about database connections; have a look at that. It tells you about connecting. The MySQL manual has details about connecting; I think it is section 19. Look where it says "Java."

Do the project in little bits, and make sure each bit works before trying the next bit.


Yes, the database is all setup and populated. Thanks for the links and suggestions, I'll go over those some more (I think I've previously reviewed them).

I spent some time with google today and it looks like JDBC pooling might be what I'm looking for. This way I do not have to create a new connection every single time I want to run a query. The way the current (PHP) application is setup, basically each time the page loads it's doing an SQL query of some sort, so if I had to create the connection as well I would probably run into performance issues. It looks like the JDBC pooling will get around that for me.
J Sellers
Greenhorn

Joined: Mar 06, 2009
Posts: 10
Just one more update as it looks like I have a lot more reading to do
I think ServletContextListener is just what I was looking for as far as the database stuff goes. I'll be working more on building out the helper classes and then actually integrating them into a webapp.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36566
    
  16
I think for JDBC pooling it would be better to continue the discussion on the JDBC forum. Moving.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "porting" a PHP application to Java...
 
Similar Threads
comparison of PHP with Ruby
minimise to systray
JSP MYSQL
unit testing approach?
Help choosing a web framework