Partner TechTip: Get Productive with PHP and Java in Just Two Minutes!

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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.pinchhittersoluitons.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).

Scott Salisbury
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: