Download Your first application using a framework

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
I04
Introduction to Java
Development with IDS
Jean Georges Perrin
IIUG
Tuesday, October 3rd 2006 • 09:00 – 10:00.
Platform: IDS, Java
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
2
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
3
Who am I?
• My Unix box usually answers…
4
Who am I (outside of a Unix box)?
•
•
•
•
Jean Georges Perrin
Development tools (xGL, Java EE, PHP)
Works with Informix products since ’97
IIUG board member
since ’02
• Lives in
Strasbourg, France
5
A little more…
• Application developer, started with Visual Basic, in
the early 90s
• In the web since 1994
• Move to 4GL in 1997
• Goals:
• Webizing all things I touched (business apps,
catalogs and i-4GL…)
• Find the ease of use of Visual Basic
6
And you…
•
•
•
•
Who knows 4GL?
Who knows Java?
Who thinks Java is difficult?
Who knows .net?
7
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
8
Architecture
Application
JDBC Driver
9
Data
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
10
Requirements
• #1 - IDS (from v7.x, but also works on OnLine and
SE)
• Where: www.iiug.org, www.informix.com
• #2 - Java (Java SDK v5.x)
• Where: www.javasoft.com
• #3 - JDBC driver (IBM Informix JDBC 3.0)
• Where: www.informix.com
• #4 - Option: Eclipse (v3.2.0)
• Where: www.eclipse.org
11
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
12
fglpc
Your very first cup of Java
fglgo
• Hello, world… in Java
• Use of “javac”
• Use of “java”
Source code is self organizing in
packages
• Code snippet:
main {…} is MAIN … END MAIN
Modules are organized in classes
package org.iiug.test;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world...");
}
}
“Hello, world…” is always the
same, in any language…
13
Java Pros & Cons
• Object Oriented (OO) development
• Event driven programming model
• User Interface (UI) & Business Logic (BL) tightly
linked
• Open architecture, open standards
• General purpose development language
• Industry standard
• Looks like “hype” to developers
14
4GL Pros & Cons
•
•
•
•
•
•
•
Procedural development
“Controlled” events
UI and BL somehow separated (.per & .4gl)
Proprietary solution
Business apps development language
Not a standard in industry
Hard to attract new developers
15
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
16
JDBC
• Types of driver (annoying theory)
• Standard way of talking to a database (forget
about SQL/J)
• Use a URL, for IBM Informix:
jdbc:informix-sqli://popeye:1526/stores_demo:
informixserver=ol_popeye;
user=informix;
password=informix
17
Agenda
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command
Prompt
• Your first application using Eclipse
• Your first application using a framework
18
Your first application using the
Command Prompt
• Understand the role of the “CLASSPATH”
• Full source code (copy / paste):
import java.sql.*;
public class MyFirstJDBCConnection {
public static void main(String[] args) {
// Define my local variables
Connection myConnection;
Statement myStatement;
ResultSet myResultSet;
// Loading driver
try {
System.out.println(">> Loading the driver");
Class.forName("com.informix.jdbc.IfxDriver");
} // end try
catch (ClassNotFoundException e) {
System.out.println("ERROR: Failed to load IBM Informix JDBC driver.");
return;
} // end catch
19
Your first application (2)
try {
// Connection to database
System.out.println(">> Connecting to the database");
myConnection = DriverManager.getConnection
("jdbc:informix-sqli://popeye:1526/stores_demo:
informixserver=ol_popeye;user=informix;password=informix",
"", "");
// Statement creation
System.out.println(">> Creating the statement");
myStatement = myConnection.createStatement();
// Resultset creation & execution
System.out.println(">> Executing the query");
myResultSet = myStatement.executeQuery
("SELECT fname, lname, customer_num FROM customer ORDER BY lname");
// Outputting the result
System.out.println(">> Step 4 - Dumping data");
while (myResultSet.next()) {
System.out.println (
myResultSet.getString("fname") +
myResultSet.getString("lname") + " (" +
myResultSet.getString("customer_num") + ")");
}
20
Your first application (3)
// Cleaning
System.out.println(">> Cleaning");
myResultSet.close();
myStatement.close();
myConnection.close();
} // end try
catch (SQLException e) {
System.out.println("ERROR: SQL exception: " + e.getMessage());
e.printStackTrace();
return;
} // end catch
} // end main
} // end class
21
Declaring objects to use
Connection = DATABASE
• Code snippet:
// Define my local variables
Connection myConnection;
Statement myStatement;
ResultSet myResultSet;
Statement = STATEMENT
• The “Connection” is the real connection to the
database, it is (re)created each time.
• Except when using “connection pooling”.
• The “Statement” is the real orders or queries to the
database.
• The “ResultSet” contains a link to the data.
ResultSet = ARRAY OF RECORD
/ CURSOR
22
Loading the driver
• Code snippet:
// Loading driver
try {
System.out.println(">> Loading the driver");
Class.forName("com.informix.jdbc.IfxDriver");
} // end try
catch (ClassNotFoundException e) {
System.out.println("ERROR: Failed to load IBM Informix JDBC driver.");
return;
} // end catch
• Drivers are uniquely named, for IBM Informix:
com.informix.jdbc.IfxDriver
23
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
24
Your first application using Eclipse
•
•
•
•
Create a project
Add the library
Create the class
Run it
25
Agenda
•
•
•
•
•
•
•
•
Who am I?
Architecture
Requirements
Your very first cup of Java
JDBC
Your first application using the Command Prompt
Your first application using Eclipse
Your first application using a framework
26
Your first application using a
framework
• Goals of a framework
• Ease of use
• Small learning curve
• Database connectivity
• Business logic
27
BlueGazelle
• Open Source framework
• Soon to be downloadable from
http://www.greenivory.com
28
BlueGazelle Source Code
Database myDatabase = null;
Record myRecord = null;
Record myRow = null;
int count = 0;
int i = 0;
try {
myDatabase = Databases.connect("stores_demo");
myRecord = myDatabase.createRecordFromSelect("SELECT fname, lname, customer_num FROM
customer ORDER BY lname");
count = myRecord.getCount();
for (i = 0; i < count; i++) {
myRow = myRecord.getRecordAt(i);
System.out.println(myRow.getString("fname")
+ myRow.getString("lname") + " ("
+ myRow.getString("customer_num") + ")");
}
}
catch (Exception e) {
System.out.println("ERROR: Exception raised: " + e.getMessage());
e.printStackTrace();
} // end catch
29
Conclusion
• Java offers a standard way of accessing data.
• Java is working in a distributed environment.
• Frameworks simplify the developers’ life.
30
And now…
• Go to my other presentation:
“Introduction to PHP development with IDS”
• (Give me good marks so I can be selected as best
speaker of the conference and beat Darryl, Lester
and Art - previous speakers).
31
And now (seriously)…
• Download Eclipse (I guess you all have IDS
already)
• Get a book (O’Reilly has quite a few great books)
• Join the development-tools forum on IIUG web site
• Get started with a few examples
32
I04
Introduction to Java Development with IDS
Jean Georges Perrin
IIUG
[email protected]
[email protected]
33