Upload
others
View
8
Download
0
Embed Size (px)
Citation preview
1
Hello Ingres!David Tondreau, Architect
A Multi-Language Introduction to Application Development on
the Ingres RDBMS
2
What Do I Do First?
Surviving Your First 30 Minutes with Ingres!
3
Agenda
• Before You Start• Installation Tips for Application Developers• Working With Ingres• Getting Started with .NET• Getting Started with Java• Getting Started with OpenROAD
4
What You'll Need
• Ingres 2006• www.ingres.com/downloads
• 4GL Developers• OpenROAD 2006 (www.ingres.com/downloads)
• Java Developers• Eclipse/Ingres/DTP Bundle (www.ingres.com/downloads)
• .NET Developers• Visual Studio
5
Useful Free Resources
• Microsoft Visual Studio Express C# Edition• msdn.microsoft.com/vstudio/express/visualcsharp/
• Sun JRE + NetBeans Bundle• java.sun.com/j2se/1.4.2/download.html
• VMWare Server• www.vmware.com/download/server/
• Acrobat Reader• www.adobe.com/products/acrobat/readstep2.html
• Info-Zip• www.info-zip.org
6
The “ingres” User Account
• Historically required for Ingres/OpenROAD• In the “Administrator” group (Windows)• Special security privileges required
• Log on as a service• Act as part of the operating system• Log on as a batch job (Everyone)
• Master DBA• Still a good idea (though not technically required)
7
Installation for Application Developers
8
Installing Ingres Components
9
Tip: Install Replicator and Federated DB
• Replicator• Built in low volume replicator service• Supports master/slave and peer to peer
• Federated Database (“Star”)• Provides a means for integrating multiple databases into a
single virtual instance
• Advanced features• Install now and turn off if you think you might want to use• Turn back on later using Ingres Configuration Manager
10
Enabling Replicator and Star
11
Tip: Increase the Size of the Ingres Log
• To support:• Importing
large test data sets
• OpenROAD
• Increase the size of the Ingres log to 200MB (or more)
• You can always do it later too
12
Tip: Select the Right Meaning of “DATE”
13
Setting the Stage
• An “ingres” account was created is logged on• Ingres 2006 r2 has been installed• Java developers:
• Have downloaded the Ingres/Eclipse/DTP bundle• Have JRE 1.5 downloaded and installed
• .NET developers:• Have Visual Studio or Visual Studio Express installed
• OpenROAD developers:• OpenROAD 2006 has been downloaded and installed
The demos in this presentation assume:
14
Working With Ingres
• Accessing the Ingres Environment• Starting and Stopping Ingres• Configuring Ingres• Creating and Destroying Databases• Using the Terminal Monitor• Backing up and Restoring Databases
15
DEMO: Accessing Ingres Command
• System Environment Variables• II_SYSTEM=C:\Program Files\Ingres\IngresII• PATH=%II_SYSTEM%\ingres\bin; %II_SYSTEM
%\ingres\utility
• On Windows• Should have been added into the system environment by
the installer
• On Linux/UNIX• Scripts “.ingIIsh” and “.ingIIcsh” are created in /home/ingres• If only one Ingres installation, add “source .ingIIsh” to your
.bashrc script
16
Starting and Stopping Ingres
• If installed as a Windows service:• Via the Windows Service Manager• Via Ingres Service Manager or Ingres Visual Manager• Via “net start|stop Ingres_Database_<II>” commands
• Linux/UNIX or not installed as Windows service• Via “ingstart” and “ingstop” commands• Must be run as a priviledged user (e.g., “ingres”)
17
Starting and Stopping Ingres (cont.)
• TIP #1: Always start Ingres as a service on Windows• If you start Ingres using ingstart on Windows, it runs under
the currently logged in account• When you log off, Ingres will shut down
• TIP #2: Don't mix start and stop as a service with ingstart and ingstop• Getting the Windows service and the running instance out of
sync causes problems
18
DEMO: Configuring Ingres Services
• Shut down Ingres• Windows: Ingres Visual Manager• Linux: “ingstop”
• Configure Ingres• Windows: Ingres Configuration Manager • Linux: Configuration by Forms (“cbf” command)
• Restart Ingres• Windows: Ingres Visual Manager• Linux: “ingstart”
19
DEMO: Creating / Destroying Databases
• On Windows:• Visual DBA• “createdb <dbname>” command• “destroydb <dbname>” command
• Warning! Destroys without a confirmation prompt!
• On Linux/UNIX• “createdb <dbname>” command• “destroydb <dbname>” command
20
Terminal Monitor (i.e., “sql” Command)
• “sql dbname” command• Allows you to run SQL statments and scripts against the
datbase interactively• Supports redirection:
• sql dbname < script.sql [ > script.log ]
• “isql dbname” command• Forms based terminal monitor
21
DEMO: Terminal Monitor Commands
• “\g” <RETURN> = GO (run the SQL)• “\q” <RETURN> = QUIT (exit Terminal Monitor)• “\r” <RETURN> = RESET/CLEAR BUFFER• “\e” <RETURN> = EDIT BUFFER• “help\g” <RETURN> = LIST USER TABLES• “help <table>” = SHOW DETAILS FOR <table>
22
Backing Up Databases
• Backing up the entire database (user+internal):• Run the “unloaddb <dbname>” command
• NOTE: ONLY generates the scripts! Does not actually run them!• Run the generated “unload.bat” command
• “unload.ing on” Linux/UNIX
• Example (with extended command syntax)
C:> cd \tempC:> mkdir testdbC:> cd testdbC:> mkdir dataC:> unloaddb testdb -source=data -dest=dataC:> unload
23
Backing Up Databases
• Backing up the user components only:• Run the “copydb dbname” command
• NOTE: ONLY generates the scripts! Does not actually run them!• Run the generated “copy.out” script using Terminal Monitor
• sql dbname < copy.out
• Example (with extended command syntax)
C:> cd \tempC:> mkdir testdbC:> cd testdbC:> mkdir dataC:> copydb testdb -source=data -dest=dataC:> sql testdb < copy.out
24
Restoring Databases
• Restoring from an Unload:• The “unloaddb” command also generated “reload.bat”
• “reload.ing on” Linux/UNIX• Create the database• Run the generated “reload.bat” command
• Example
C:> cd \tempC:> cd testdbC:> createdb testdbC:> reload.bat
25
Restoring Databases
• Restoring user components only:• The “copydb” command also created a “copy.in” script• Create the database• Run the generated “copy.in” script using Terminal Monitor
• sql dbname < copy.in
• Example (with extended command syntax)
C:> cd \tempC:> cd testdbC:> createdb testdbC:> sql testdb < copy.in
26
Special Note for OpenROAD Developers
• OpenROAD stores all applications and source components in the Ingres internal system catalogs
• Unloaddb will back up your applications• Copydb will not back up your applications• “w4gldev backupapp out <db> <app> <file>” can
also be used
27
Getting Started with .NET
• Create a C# project• Add the Ingres .NET Data Provider to the project• Add an entry field to the form• Add the code to:
• Connect to Ingres• Set up and run a query• Put the data on the form• Disconnect from Ingres
28
.NET Code Snippet
using Ingres.Client; ... string location = "Host=localhost;" + "User Id=ingres;PWD=password;" + "Database=testdb"; IngresConnection dbConn = new IngresConnection(location); dbConn.Open(); string sql = "select text from greeting"; IngresCommand ingCmd = new IngresCommand(sql, dbConn); IngresDataReader dataReader = ingCmd.ExecuteReader(); dataReader.Read(); text.Text = dataReader.GetString(0); dataReader.Close(); dbConn.Close();
29
Getting Started with Java
• Create a Java project• Add the Ingres JDBC Driver to the project• Add the code to:
• Connect to Ingres• Set up and run a query• Write out the value on the console• Disconnect from Ingres
30
Java Snippetimport java.sql.Connection;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import com.ingres.jdbc.*;public final class Application { public static void main(String[] args) { IngresDataSource dataSource = new IngresDataSource (); Connection dbConn = null; PreparedStatement statement = null; ResultSet results = null; String text = ""; dataSource.setServerName("localhost"); dataSource.setDatabaseName("testdb"); dataSource.setPortName("II7"); dataSource.setUser("ingres"); dataSource.setPassword("password"); try { dbConn = dataSource.getConnection(); statement = dbConn.prepareStatement("SELECT text FROM greeting"); results = statement.executeQuery(); results.next(); text = (String) results.getObject(1); System.out.println(text); dbConn.close(); } catch (SQLException e) { e.printStackTrace(); } }}
31
Getting Started with OpenROAD
• Connect to the Database• Create an Application• Create a Frame• Create an Entry Field• Write the SQL
32
OpenROAD Code Snippet SELECT :text = text FROM greeting; COMMIT;
34
More Questions? See You In The Forums!