Partner TechTip: Get Productive with PHP and Java in Just Two Minutes! PDF Print E-mail
Tips & Techniques - Programming
Written by Scott Salisbury   
Wednesday, 21 May 2008

Article Sponsor

Pinch_Hitter_Logo.jpg

Pinch Hitter Solutions

Address
PO BOX 223, Thompsons Station, TN, USA, 37179
Phone
800.653.7404 x702
E-mail
Website
http://www.pinchhittersolutions.com/index.html
Products

Pinch Hitter Solutions was formed in 2005. We build software products geared to take the tedium out of applications database work. Our goal is to provide software developers with easy access to all common enterprise database technologies regardless of their development platform.

 

 

Do you want to harness the power of PHP or Java but find it difficult to stop everything and learn these technologies?

 

Lots of books and training materials are available for Java and PHP, but the best education is seeing these languages as they interact with your own data. When developers decide to learn a new language, one of the first questions that occur to them is along the lines of, "How do I use Java (or PHP, or whatever) to access my own data?" There is something very meaningful and ultimately educational about seeing a new language wrapped around your own tables and columns. It helps bridge the gap between the known and the unknown in a very tangible way.

 

If learning Java or PHP is on your radar, then check out SQL(snap) for a quick start.

 

As programmers, we want to be productive immediately. I suppose there is something to be said for "Hello World" programs, but as a seasoned developer, I want to skip ahead. I want to do something productive today. I want it now! If I can learn something practical right away, I am more inclined to continue the educational process. If I have to yawn through hours of theory and obtuse examples, I usually table it for another day, which ultimately never comes.

 

SQL(snap) is a rapid development engine that generates Java and PHP (and RPG) based on SQL queries that you execute against your own data! This means you can immediately learn how Java and PHP are used to interact with your own tables and columns.

 

Let's examine a common scenario that SQL(snap) resolves easily and that provides ample education at the same time. For this example, we'll use Java. Imagine that your Web site order table is on MS SQL Server and contains customer items purchased from your online store. Now, let's say that once every hour you want to copy new orders to DB2/400 so your fulfillment function can process the orders. Let's move in a little closer and examine the steps for solving this problem.

 

Step 1: Build and execute a query of the Web orders table. See Figure 1.

 

052108Scottfigure_1.jpg

Figure 1: Easily build a query by typing it, or build it with a few clicks.

 

Step 2: Now that we have determined the query we want to generate Java code for, we select "Java SQL" from the System i drop-down list and click "Generate Code." See Figure 2.

 

052108Scottfigure_2.jpg

Figure 2: Select "Java SQL" to generate a Java class around this query.

 

Step 3: Export the Java class for use in WDSC or any IDE. See Figure 3.

 

052108Scottfigure_3.jpg

Figure 3: Generated Java code is exported for use in your IDE.

 

Figure 3 shows the code necessary to iterate the result set created by our query from Figure 1.

Here are the steps that were automatically created by SQL(snap) from Figure 3.

 

A.  Create a prepared statement object. Note that the values from the WHERE clause used in Figure 1 have been replaced by question marks. This is part of parameterizing the prepared statement for using different values at run time.

B.  Declare the prepared statement variables based on the WHERE clause values used in Figure 1. (These can be changed at run time for greater flexibility)

C.  Load the prepared statement parameters.

D.  Execute the query.

E.  Iterate the result set, loading the working variables with data from the actual table.

F.  Clean house.

 

Our mission was to create a Java class that would read our Web orders table from MS SQL Server and write that data to DB2/400. Here, I have shown how easy it is to generate the Java used for the first part, which was to read the data from SQL Server. It took less than a minute to do this.

 

In the interest of space, the code used to update DB2/400 was not shown here. To see all the code needed for this example, visit our Web site and click on "articles."

 

SQL(snap) has lots of other useful features, so click over to http://www.sqlsnap.com/ and get your free 30-day trial, pricing information, and special offers. You can also download our white papers and see video tutorials for SQL(snap).


Last Updated ( Wednesday, 21 May 2008 )
 
Discuss (2 posts)
S.Salisbury
Re:Partner TechTip: Get Productive with PHP and Java in Just Two Minutes!
May 23 2008 17:41:00
One of the cool things about SQL(snap) is that it runs in the browser, so if SQL(snap) is running on your box, then your box is acting as the server. Anyone on the network that can see your machine can also see
SQL(snap). Just give everyone this URL:

http://yourmachinename:8099/sqlsnap and they will be good to go.

Scott
#121882
npryor
Partner TechTip: Get Productive with PHP and Java in Just Two Minutes!
May 22 2008 18:13:28
This thread discusses the Content article: Partner TechTip: Get Productive with PHP and Java in Just Two Minutes!

I've downloaded sqlsnap to my workstation. Is it OK for other users to connect and evaluate it with me or does each user need to install?
#121880


Discuss...
User Rating: / 1
PoorBest 

Scott Salisbury
About the Author:

Scott Salisbury is a writer, consultant, and software architect for Pinch Hitter Solutions in the Nashville, Tennessee , area. Scott has worked with the System i, iSeries, and AS/400 since its introduction in 1988. He has been working with Java since 1999 and PHP since 2007. 

 

Contact Scott at This e-mail address is being protected from spam bots, you need JavaScript enabled to view it or 800.653.7404x704.

Related Articles
< Prev   Next >
   MC-STORE.COM