Créating sweet interfaces with Swing and Awt
--
Alain Lompo
Excelta - Conseils et services informatiques
MCT
MCSD For Microsoft .Net
MVP Windows Systems Server / Biztalk Server
Certifié ITIL et Microsoft Biztalk Server
| Product | Novoya 1.4 | NovusCMS 4.5 | OpenCms 7.0.4 | Polaris CMS 1.2 | Roxen CMS 4.0 | smartCMS 2 | TCMS 1.0 | XCMS |
| Last Updated | 2/24/2008 | 4/21/2008 | 3/25/2008 | 9/9/2005 | 8/25/2004 | 11/6/2006 | 9/15/2004 | 10/25/2004 |
| System Requirements | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Application Server | .Net 2.0 / IIS | Tomcat, JBoss, Resin 3, Websphere 6 | IIS + ASP.NET | 4 or more | ASP, ASP.NET | .NET | none required | |
| Approximate Cost | $19,500 | Free | n.n.t.b. | 15.000 euro | $90 per month or $7,000 per CPU | |||
| Database | MySQL, Postgres, mSQL, Interbase, Sybase | Microsoft SQL Server | AS400 | 2000 | and DB | Microsoft SQL Server 2000 | Microsoft SQL Server 2000 | built-in (none required) |
| License | Flat-fee | GNU LGPL | Commercial | Commercial, includes full source code | Commercial, Annual | Flexible | Commercial per installation | |
| Operating System | Any | Windows Server 2000/2003 | Any | Windows Server 2003 | Windows, Macintosh, Linux, Unix | Windows Server 2000/2003 | 2003, 2000, XP-Pro | Any |
| Programming Language | PHP 5.2+ | .NET, C#, XSLT, ASP.NET | Java 1.4. + | C# | pike | ASP, .NET, extendable via Web Services | Asp.Net | Perl 5.6+ |
| Root Access | No | Yes | No | Yes | Yes | No | ||
| Shell Access | No | Yes | No | Yes | No | No | ||
| Web Server | Apache | IIS | IIS, Apache | IIS | IIS 5.0 & IIS 6.0 | IIS | Apache, IIS | |
| Security | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Audit Trail | No | Yes | Yes | Yes | Yes | No | No | Limited |
| Captcha | Yes | Yes | Yes | No | No | |||
| Content Approval | No | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Email Verification | Limited | Yes | No | No | No | |||
| Granular Privileges | No | Yes | Yes | Yes | Yes | Yes | Yes | Limited |
| Kerberos Authentication | No | No | No | No | No | No | No | No |
| LDAP Authentication | No | Costs Extra | Costs Extra | No | Yes | No | No | Costs Extra |
| Login History | No | Yes | Yes | Yes | Yes | No | No | Yes |
| NIS Authentication | No | No | No | No | Yes | No | No | No |
| NTLM Authentication | No | No | No | No | Yes | No | No | No |
| Pluggable Authentication | No | No | Costs Extra | No | Yes | No | Costs Extra | Costs Extra |
| Problem Notification | Yes | No | Yes | Yes | Yes | No | No | Costs Extra |
| Sandbox | No | Yes | Yes | Yes | Yes | No | Yes | Yes |
| Session Management | Yes | No | No | Yes | Yes | No | No | Limited |
| SMB Authentication | No | No | No | No | Yes | No | No | No |
| SSL Compatible | No | Yes | Yes | Yes | Yes | No | No | Costs Extra |
| SSL Logins | No | Yes | Yes | Yes | Yes | No | No | Costs Extra |
| SSL Pages | No | Yes | Yes | Yes | Yes | No | No | Costs Extra |
| Versioning | No | Yes | Yes | Yes | Yes | Yes | No | Limited |
| Support | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Certification Program | No | No | No | No | Yes | No | No | No |
| Code Skeletons | Yes | No | No | No | ||||
| Commercial Manuals | No | Yes | Yes | No | Yes | Yes | No | No |
| Commercial Support | No | Yes | Yes | Yes | Yes | No | Yes | Limited |
| Commercial Training | No | Yes | Yes | No | Yes | Yes | Yes | Limited |
| Developer Community | No | No | Yes | No | Yes | No | No | No |
| Online Help | No | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Pluggable API | No | No | Yes | Yes | Yes | No | Yes | Limited |
| Professional Hosting | Free Add On | Yes | Limited | Yes | Yes | Yes | Yes | No |
| Professional Services | No | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Public Forum | Yes | Yes | Yes | No | Yes | No | No | No |
| Public Mailing List | No | No | Yes | No | Yes | Yes | No | No |
| Test Framework | No | No | Yes | Yes | ||||
| Third-Party Developers | No | No | Yes | No | Yes | No | Yes | No |
| Users Conference | No | No | Limited | No | Yes | No | No | No |
| Ease of Use | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Drag-N-Drop Content | Yes | Yes | Limited | No | Limited | Yes | No | Yes |
| Email To Discussion | No | Yes | No | Yes | Yes | No | No | Costs Extra |
| Friendly URLs | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Image Resizing | Yes | No | Yes | No | Yes | |||
| Macro Language | No | Yes | No | No | Yes | No | No | Yes |
| Mass Upload | No | No | Yes | Yes | No | |||
| Prototyping | No | No | No | No | No | |||
| Server Page Language | No | Yes | Yes | Yes | Yes | Yes | Yes | No |
| Site Setup Wizard | No | No | No | |||||
| Spell Checker | No | Yes | Free Add On | Yes | No | No | Limited | |
| Style Wizard | No | Yes | No | Yes | ||||
| Subscriptions | No | Yes | Costs Extra | Yes | Yes | No | ||
| Template Language | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes |
| UI Levels | Yes | Yes | Yes | No | Yes | Yes | Costs Extra | No |
| Undo | No | Yes | Yes | No | Yes | No | Yes | Limited |
| WYSIWYG Editor | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Zip Archives | No | No | Limited | No | ||||
| Performance | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Advanced Caching | No | No | Yes | Yes | Yes | Yes | Yes | No |
| Database Replication | No | No | Costs Extra | Yes | Yes | Yes | No | No |
| Load Balancing | No | No | Costs Extra | Yes | Yes | Yes | Costs Extra | Costs Extra |
| Page Caching | Yes | No | Yes | Yes | Yes | Yes | Yes | No |
| Static Content Export | No | No | Yes | No | Yes | No | Yes | |
| Management | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Advertising Management | No | No | No | Yes | No | Yes | No | Costs Extra |
| Asset Management | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| Clipboard | No | Yes | No | Yes | Yes | Yes | Yes | Yes |
| Content Scheduling | Yes | Yes | Yes | Yes | Yes | Yes | No | Costs Extra |
| Content Staging | No | No | Limited | Yes | Yes | No | Costs Extra | Costs Extra |
| Inline Administration | No | No | Limited | No | Yes | No | Yes | Yes |
| Online Administration | Yes | Yes | Yes | Yes | Yes | No | Yes | Yes |
| Package Deployment | No | Yes | Limited | No | Yes | No | No | Yes |
| Sub-sites / Roots | No | Yes | Yes | Yes | Yes | No | Yes | Yes |
| Themes / Skins | Yes | Yes | No | Yes | Yes | No | No | Yes |
| Trash | No | Yes | Yes | No | Yes | No | No | No |
| Web Statistics | No | No | No | Yes | Yes | Yes | No | No |
| Web-based Style/Template Management | Yes | Yes | Limited | No | Yes | No | Limited | Yes |
| Web-based Translation Management | Yes | No | No | No | Yes | Yes | No | No |
| Workflow Engine | No | No | Free Add On | Yes | Yes | No | No | Costs Extra |
| Interoperability | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Content Syndication (RSS) | Yes | Yes | Costs Extra | No | Yes | No | Costs Extra | Costs Extra |
| FTP Support | No | No | No | No | Yes | Yes | No | No |
| iCal | No | No | No | |||||
| UTF-8 Support | Yes | No | Yes | Yes | Yes | No | No | Limited |
| WAI Compliant | No | No | Limited | No | Yes | Yes | No | Yes |
| WebDAV Support | No | No | Yes | No | Yes | No | No | No |
| XHTML Compliant | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes |
| Flexibility | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| CGI-mode Support | No | No | No | No | Yes | No | No | Yes |
| Content Reuse | No | No | Yes | Yes | Yes | No | Yes | Costs Extra |
| Extensible User Profiles | No | No | Yes | Yes | Yes | No | No | No |
| Interface Localization | Limited | No | Yes | Yes | Yes | No | No | Costs Extra |
| Metadata | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes |
| Multi-lingual Content | No | No | Yes | Yes | Yes | Yes | No | Yes |
| Multi-lingual Content Integration | No | No | Yes | Yes | Yes | Yes | No | No |
| Multi-Site Deployment | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| URL Rewriting | Yes | No | Yes | Yes | Yes | No | Yes | Yes |
| Built-in Applications | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Blog | Yes | No | No | No | No | No | No | No |
| Chat | No | No | No | No | No | No | No | No |
| Classifieds | No | No | No | Yes | Costs Extra | No | Costs Extra | No |
| Contact Management | Yes | No | No | Yes | No | No | No | No |
| Data Entry | No | No | No | Limited | Yes | No | No | No |
| Database Reports | No | No | Costs Extra | No | Costs Extra | No | No | No |
| Discussion / Forum | No | No | Free Add On | Yes | Yes | No | Costs Extra | Yes |
| Document Management | No | No | No | No | No | No | No | No |
| Events Calendar | No | No | Costs Extra | No | Costs Extra | No | Costs Extra | No |
| Events Management | No | No | No | Yes | ||||
| Expense Reports | No | No | No | No | No | No | No | No |
| FAQ Management | No | No | Free Add On | Yes | Costs Extra | No | Free Add On | No |
| File Distribution | No | No | No | No | Yes | No | No | Costs Extra |
| Graphs and Charts | No | No | No | No | Yes | No | Costs Extra | No |
| Groupware | No | No | No | No | No | No | No | No |
| Guest Book | No | No | No | No | Yes | No | No | No |
| Help Desk / Bug Reporting | No | Yes | No | Yes | No | No | No | No |
| HTTP Proxy | No | No | No | Yes | Yes | No | No | No |
| In/Out Board | No | No | No | No | Costs Extra | No | No | No |
| Job Postings | No | No | Costs Extra | No | Costs Extra | No | Costs Extra | No |
| Link Management | Yes | Yes | Yes | Yes | Costs Extra | No | Costs Extra | Yes |
| Mail Form | No | Yes | Yes | Yes | Costs Extra | No | Free Add On | Yes |
| Matrix | No | No | No | No | ||||
| My Page / Dashboard | No | No | No | Yes | Yes | No | No | No |
| Newsletter | No | No | Free Add On | Yes | No | No | ||
| Photo Gallery | No | Yes | Yes | No | Yes | Yes | Free Add On | No |
| Polls | No | No | Free Add On | Yes | Costs Extra | No | Free Add On | No |
| Product Management | No | No | Costs Extra | Yes | Yes | No | Free Add On | No |
| Project Tracking | No | No | No | No | No | No | No | No |
| Search Engine | Yes | Yes | Yes | Yes | Yes | Yes | No | Yes |
| Site Map | Yes | No | Yes | Yes | Yes | No | ||
| Stock Quotes | No | No | No | No | ||||
| Surveys | No | No | No | No | No | No | Costs Extra | No |
| Syndicated Content (RSS) | No | Yes | Costs Extra | No | Yes | No | Costs Extra | No |
| Tests / Quizzes | No | No | No | Yes | No | No | No | No |
| Time Tracking | No | No | No | No | No | No | Costs Extra | No |
| User Contributions | No | No | No | No | Yes | No | No | No |
| Weather | No | No | No | Yes | ||||
| Web Services Front End | No | No | No | No | No | No | No | No |
| Wiki | No | No | No | No | No | No | No | No |
| Commerce | Novoya | NovusCMS | OpenCms | Polaris CMS | Roxen CMS | smartCMS | TCMS | XCMS |
| Affiliate Tracking | No | No | No | No | Yes | Yes | No | Costs Extra |
| Inventory Management | No | No | No | No | Yes | |||
| Pluggable Payments | No | No | No | No | No | |||
| Pluggable Shipping | No | No | No | No | No | |||
| Pluggable Tax | No | No | No | No | No | |||
| Point of Sale | No | No | No | No | No | |||
| Shopping Cart | No | No | Free Add On | No | Costs Extra | Yes | Free Add On | Yes |
| Subscriptions | No | No | No | No | Yes | |||
| Wish Lists | No | No | No | No | Yes |
http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html
A J2EE application is delivered in an Enterprise Archive (EAR) file, a standard Java Archive (JAR) file with an .ear extension. Using EAR files and modules makes it possible to assemble a number of different J2EE applications using some of the same components. No extra coding is needed; it is only a matter of assembling (or packaging) various J2EE modules into J2EE EAR files.
An EAR file (see Figure 1-6) contains J2EE modules and deployment descriptors. A deployment descriptor is an XML document with an .xml extension that describes the deployment settings of an application, a module, or a component. Because deployment descriptor information is declarative, it can be changed without the need to modify the source code. At runtime, the J2EE server reads the deployment descriptor and acts upon the application, module, or component accordingly.
There are two types of deployment descriptors: J2EE and runtime. A J2EE deployment descriptor is defined by a J2EE specification and can be used to configure deployment settings on any J2EE-compliant implementation. A runtime deployment descriptor is used to configure J2EE implementation-specific parameters. For example, the Sun Java System Application Server Platform Edition 8 runtime deployment descriptor contains information such as the context root of a web application, the mapping of portable names of an application's resources to the server's resources, and Application Server implementation-specific parameters, such as caching directives. The Application Server runtime deployment descriptors are named sun-moduleType.xml and are located in the same directory as the J2EE deployment descriptor.
A J2EE module consists of one or more J2EE components for the same container type and one component deployment descriptor of that type. An enterprise bean module deployment descriptor, for example, declares transaction attributes and security authorizations for an enterprise bean. A J2EE module without an application deployment descriptor can be deployed as a stand-alone module. The four types of J2EE modules are as follows:
.jar extension..war (web archive) extension..jar extension..rar (resource adapter archive) extension
Web Services Support
Web services are web-based enterprise applications that use open, XML-based standards and transport protocols to exchange data with calling clients. The J2EE platform provides the XML APIs and tools you need to quickly design, develop, test, and deploy web services and clients that fully interoperate with other web services and clients running on Java-based or non-Java-based platforms.
To write web services and clients with the J2EE XML APIs, all you do is pass parameter data to the method calls and process the data returned; or for document-oriented web services, you send documents containing the service data back and forth. No low-level programming is needed because the XML API implementations do the work of translating the application data to and from an XML-based data stream that is sent over the standardized XML-based transport protocols. These XML-based standards and protocols are introduced in the following sections.
The translation of data to a standardized XML-based data stream is what makes web services and clients written with the J2EE XML APIs fully interoperable. This does not necessarily mean that the data being transported includes XML tags because the transported data can itself be plain text, XML data, or any kind of binary data such as audio, video, maps, program files, computer-aided design (CAD) documents and the like. The next section introduces XML and explains how parties doing business can use XML tags and schemas to exchange data in a meaningful way.
XML
XML is a cross-platform, extensible, text-based standard for representing data. When XML data is exchanged between parties, the parties are free to create their own tags to describe the data, set up schemas to specify which tags can be used in a particular kind of XML document, and use XML stylesheets to manage the display and handling of the data.
For example, a web service can use XML and a schema to produce price lists, and companies that receive the price lists and schema can have their own stylesheets to handle the data in a way that best suits their needs. Here are examples:
- One company might put XML pricing information through a program to translate the XML to HTML so that it can post the price lists to its intranet.
- A partner company might put the XML pricing information through a tool to create a marketing presentation.
- Another company might read the XML pricing information into an application for processing.
SOAP Transport Protocol
Client requests and web service responses are transmitted as Simple Object Access Protocol (SOAP) messages over HTTP to enable a completely interoperable exchange between clients and web services, all running on different platforms and at various locations on the Internet. HTTP is a familiar request-and response standard for sending messages over the Internet, and SOAP is an XML-based protocol that follows the HTTP request-and-response model.
The SOAP portion of a transported message handles the following:
- Defines an XML-based envelope to describe what is in the message and how to process the message
- Includes XML-based encoding rules to express instances of application-defined data types within the message
- Defines an XML-based convention for representing the request to the remote service and the resulting response
WSDL Standard Format
The Web Services Description Language (WSDL) is a standardized XML format for describing network services. The description includes the name of the service, the location of the service, and ways to communicate with the service. WSDL service descriptions can be stored in registries or published on the web (or both). The Sun Java System Application Server Platform Edition 8 provides a tool for generating the WSDL specification of a web service that uses remote procedure calls to communicate with clients.
UDDI and ebXML Standard Formats
Other XML-based standards, such as Universal Description, Discovery and Integration (UDDI) and ebXML, make it possible for businesses to publish information on the Internet about their products and web services, where the information can be readily and globally accessed by clients who want to do business.
The J2EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function, and the various application components that make up a J2EE application are installed on different machines depending on the tier in the multitiered J2EE environment to which the application component belongs. Figure 1-1 shows two multitiered J2EE applications divided into the tiers described in the following list. The J2EE application parts shown in Figure 1-1 are presented in J2EE Components.
Although a J2EE application can consist of the three or four tiers shown in Figure 1-1, J2EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three locations: client machines, the J2EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client and server model by placing a multithreaded application server between the client application and back-end storage.
Figure 1-1 Multitiered Applications
J2EE applications are made up of components. A J2EE component is a self-contained functional software unit that is assembled into a J2EE application with its related classes and files and that communicates with other components. The J2EE specification defines the following J2EE components:
J2EE components are written in the Java programming language and are compiled in the same way as any program in the language. The difference between J2EE components and "standard" Java classes is that J2EE components are assembled into a J2EE application, are verified to be well formed and in compliance with the J2EE specification, and are deployed to production, where they are run and managed by the J2EE server.
A J2EE client can be a web client or an application client.
A web client consists of two parts: (1) dynamic web pages containing various types of markup language (HTML, XML, and so on), which are generated by web components running in the web tier, and (2) a web browser, which renders the pages received from the server.
A web client is sometimes called a thin client. Thin clients usually do not query databases, execute complex business rules, or connect to legacy applications. When you use a thin client, such heavyweight operations are off-loaded to enterprise beans executing on the J2EE server, where they can leverage the security, speed, services, and reliability of J2EE server-side technologies.
A web page received from the web tier can include an embedded applet. An applet is a small client application written in the Java programming language that executes in the Java virtual machine installed in the web browser. However, client systems will likely need the Java Plug-in and possibly a security policy file in order for the applet to successfully execute in the web browser.
Web components are the preferred API for creating a web client program because no plug-ins or security policy files are needed on the client systems. Also, web components enable cleaner and more modular application design because they provide a way to separate applications programming from web page design. Personnel involved in web page design thus do not need to understand Java programming language syntax to do their jobs.
An application client runs on a client machine and provides a way for users to handle tasks that require a richer user interface than can be provided by a markup language. It typically has a graphical user interface (GUI) created from the Swing or the Abstract Window Toolkit (AWT) API, but a command-line interface is certainly possible.
Application clients directly access enterprise beans running in the business tier. However, if application requirements warrant it, an application client can open an HTTP connection to establish communication with a servlet running in the web tier.
Component Architecture The server and client tiers might also include components based on the JavaBeans component architecture (JavaBeans components) to manage the data flow between an application client or applet and components running on the J2EE server, or between server components and a database. JavaBeans components are not considered J2EE components by the J2EE specification.
JavaBeans components have properties and have get and set methods for accessing the properties. JavaBeans components used in this way are typically simple in design and implementation but should conform to the naming and design conventions outlined in the JavaBeans component architecture.
Figure 1-2 shows the various elements that can make up the client tier. The client communicates with the business tier running on the J2EE server either directly or, as in the case of a client running in a browser, by going through JSP pages or servlets running in the web tier.
Your J2EE application uses a thin browser-based client or thick application client. In deciding which one to use, you should be aware of the trade-offs between keeping functionality on the client and close to the user (thick client) and off-loading as much functionality as possible to the server (thin client). The more functionality you off-load to the server, the easier it is to distribute, deploy, and manage the application; however, keeping more functionality on the client can make for a better perceived user experience.
Figure 1-2 Server Communications
J2EE web components are either servlets or pages created using JSP technology (JSP pages). Servlets are Java programming language classes that dynamically process requests and construct responses. JSP pages are text-based documents that execute as servlets but allow a more natural approach to creating static content.
Static HTML pages and applets are bundled with web components during application assembly but are not considered web components by the J2EE specification. Server-side utility classes can also be bundled with web components and, like HTML pages, are not considered web components.
As shown in Figure 1-3, the web tier, like the client tier, might include a JavaBeans component to manage the user input and send that input to enterprise beans running in the business tier for processing.
Business code, which is logic that solves or meets the needs of a particular business domain such as banking, retail, or finance, is handled by enterprise beans running in the business tier. Figure 1-4 shows how an enterprise bean receives data from client programs, processes it (if necessary), and sends it to the enterprise information system tier for storage. An enterprise bean also retrieves data from storage, processes it (if necessary), and sends it back to the client program.
Figure 1-3 Web Tier and J2EE Applications
Figure 1-4 Business and EIS Tiers
There are three kinds of enterprise beans: session beans, entity beans, and message-driven beans. A session bean represents a transient conversation with a client. When the client finishes executing, the session bean and its data are gone. In contrast, an entity bean represents persistent data stored in one row of a database table. If the client terminates or if the server shuts down, the underlying services ensure that the entity bean data is saved. A message-driven bean combines features of a session bean and a Java Message Service (JMS) message listener, allowing a business component to receive JMS messages asynchronously.
The enterprise information system tier handles EIS software and includes enterprise infrastructure systems such as enterprise resource planning (ERP), mainframe transaction processing, database systems, and other legacy information systems. For example, J2EE application components might need access to enterprise information systems for database connectivity
--
Alain Lompo
Excelta - Conseils et services informatiques
MCT
MCSD For Microsoft .Net
MVP Windows Systems Server / Biztalk Server
Certifié ITIL et Microsoft Biztalk Server
Dansing Java is too easy !!!
La technologie JDBC (Java DataBase Connectivity) est un ensemble de classes permettant de développer des applications capables de se connecter à des serveurs de bases de données (SGBD).
Dans un système client/serveur, l'accès aux bases de données avec JDBC peut s'effectuer selon un modèle à deux couches ou bien un modèle à trois couches.
Pour le modèle à deux couches, une application Java est intimement liée avec une base de données. A cet effet, il faut bien évidemment disposer, pour la base de données concernée, d'un pilote JDBC adéquat. Les instructions SQL sont directement envoyées à la base, cette dernière renvoyant les résultats par un biais tout aussi direct. La base de données peut être exécutée sur la machine locale (celle sur laquelle l'application Java fonctionne) ou bien sur tout autre ordinateur du réseau (Intranet ou Internet).
Dans le modèle à 3 couches, une troisième couche (le serveur d'application) vient s'intercaler entre l'application Java et la base de données. Les instructions SQL et les résultats livrés en retour y transitent. Ce modèle présente l'avantage d'intégrer dans cette couche un contrôle d'accès.
Les pilotes actuels sont classés en quatre catégories :
ODBC signifie Open Database Connectivity. Il s'agit d'un format propriétaire défini par Microsoft permettant la communication entre des clients pour bases de données fonctionnant sous Windows et les SGBD du marché.
Etant donné qu'il existe différents types de bases de données, et que chacune d'entre-elles possède sa propre façon de traiter les requêtes SQL et de renvoyer les résultats, ODBC permet d'obtenir des résultats identiques quel que soit le type de base de données, sans avoir à modifier le programme d'appel qui transmet la requête.
ODBC n'est toutefois pas la solution miracle, étant donné d'une part qu'il ne s'agit pas d'une technologie libre (Microsoft la fait évoluer à son gré), d'autre part qu'il ne s'agit que d'une interface "alternative" à celle fournie par les constructeurs et compliquée à maîtriser.
Afin d'illustrer la connexion à une base de données, nous allons nous connecter à une base Access par l'intermédiaire de la passerelle ODBC-JDBC, en abordant toutes les étapes de la connexion à une base de données.
Après création de la base sous Access, il faut dans un premier temps intégrer la base dans l'administrateur de source de données ODBC (Panneau de configuration / source de données ).
Les étapes de création de la source ODBC sont :
L'API (Application Programming Interface) JDBC, c'est-à-dire la bibliothèque de classes JDBC, se charge de trois étapes indispensables à la connexion à une base de données :
Tous les objets et les méthodes relatifs aux bases de données sont présentes dans le package java.sql, il est donc indispensable d'importer java.sql.* dans tout programme se servant de la technologie JDBC.
Pour se connecter à une base de données déclarée dans l'administrateur ODBC, il est essentiel de charger dans un premier temps le pilote JDBC-ODBC (appelé pont JDBC-ODBC) :
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");Cette instruction charge le pilote et crée une instance de cette classe. Pour se connecter à une base de données particulière, il s'agit ensuite de créer une instance de la classe Connection en indiquant la base de données à charger à l'aide de son URL String url = "jdbc:odbc:base_de_donnees"; Connection con = DriverManager.getConnection(url);Le nom de la base de données (ici base_de_donnees) étant celle déclarée dans le panneau de configuration ODBC. La syntaxe de l'URL peut varier légèrement selon le type de la base de données. Il s'agit généralement d'une adresse de la forme :
jdbc:sousprotocole:nom
Pour exécuter une requête SQL, il s'agit dans un premier temps de créer un objet Statement, pouvant être obtenu à partir de l'objet Connection. Un objet ResultSet permettra de récupérer les données en provenance de l'objet Statement.
String query = "SELECT * FROM Ma_Table;"; ResultSet results; try { Statement stmt = con.createStatement(); results = stmt.executeQuery(query); } catch(Exception e){ System.out.println("exception du a la requete"); } Une fois la connexion à la base de données établie, il est possible de demander des informations sur le nom des tables et le contenu de chaque colonne, ainsi que d'exécuter des requêtes SQL afin de récupérer des informations, d'en ajouter ou bien de les modifier.
Les objets utilisables pour obtenir des informations sur la base sont :
Toutefois, seul un nombre réduit des méthodes de chacun de ces objets permet d'obtenir les informations les plus importantes sur les données.
L'objet ResultSet est l'objet le plus important de la technologie JDBC, car il s'agit d'une abstraction de la table ou de la réponse à une requête (généralement un sous-ensemble d'une table). Ainsi, presque toutes les méthodes et requêtes retournent les données sous forme d'un objet ResultSet. Cet objet contient un nombre donné de colonnes repérées chacune par un nom, ainsi qu'une ou plusieurs lignes contenant les données, et auxquelles il est possible d'accèder séquentiellement une à une du haut vers le bas. Ainsi, afin d'exploiter un objet ResultSet, il est nécessaire de récupérer le nombre de colonnes de celui-ci, à l'aide de l'objet ResultSetMetaData.
ResultSetMetaData rsmd; rsmd = results.getMetaData(); numcols = rsmd.getColumnCount();Lors de l'obtention d'un objet ResultSet, le descripteur pointe avant la première ligne.
La méthode next() permet d'obtenir chacune des lignes suivantes, et retourne false lorsqu'il ne reste plus aucune ligne. Etant donné que l'extraction de données de la base peut générer des erreurs, il est indispensable d'inclure ces manipulations dans un bloc d'exception (try).
Les données contenues dans le ResultSet peuvent être obtenues sous différentes formes selon le type de données stockées dans chaque colonne. Le contenu de chaque colonne peut être obtenu soit par le nom de celle-ci, soit par son numéro (sachant que les numéros de colonne commencent à 1 et non à 0).
Les principales méthodes de l'objet ResultSet sont les suivantes :
L'objet ResultSetMetaData (obtenu de l'objet ResultSet) permet de connaître le nombre, le nom et le type de chaque colonne à l'aide des méthodes suivantes :
Puisque l'accès à une base de données nécessite l'utilisation conjointe de plusieurs objets, il peut être intéressant de créer quelques objets de plus haut niveau encapsulant la plupart des comportements cités ci-dessus.
Ainsi la création d'un objet DataBase pour permettre d'encapsuler l'ensemble des objets nécessaires à la connexion à une base de données (Connection, Statement, DataBaseMetaData), ainsi que de (re)définir des méthodes simples permettant de rendre plus simples certaines opérations, comme la création de la connexion, la récupération du nom des tables, ainsi qu'une méthode Execute rendant l'exécution de requête triviale.
class Database { Connection con; resultSet results; ResultSetMetaData rsmd; DatabaseMetaData dm; String catalog; String types[]; //---------------------------- public Database(String Driver) { types = new String[1]; types[0] = "TABLES"; try { Class.forName(driver); } catch(Exception e){ System.out.println("Erreur lors du chargement du driver:"+ e.getMessage()); } } //------------------------------------------------------ public void Open(String url,String login,String password) { try{ con = DriverManager.getConnection(url,login,password); dma = con.getMetaData(); results = new resultSet(dma.getCatalogs()); String s[]; while(results.hasMoreElements()) { s = results.NetxElement(); } } catch(Exception e){ System.out.println("echec d'ouverture:"+e.getMessage()); } } //----------------- public void Close() { try{ con.close(); } catch(Exception e){ System.out.println("echec lors de la fermeture:"+e.getMessage()); } } //----------------------------- public String[] getTableNames() { String[] tbnames = null; Vector tname = new Vector(); try{ results = new resultSet(dma.getTables(catalog,null,"%",types)); while (results.hasMoreElements()) tname.addElement(results.getColumnValue("TABLE_NAME")); } catch(Exception e){ System.out.println(e.getMessage()); } tbnames = new String[tname.size()]; for(int i=0;i<tname.size();i++) tbnames[i] = (String)tname.elementAt(i); return tbnames; } //-------------------------------- public String[] getTableMetaData() { results = null; try{ results = new resultSet(dma.getTables(catalog,null,"%",types)); } catch(Exception e){ System.out.println(e.getMessage()); } return results.getMetaData(); } //------------------------------------------------ public String[] getColumnMetaData(String tablename) { results = null; try{ results = new resultSet(dma.getTables(catalog,null,tablename,null)); } catch(Exception e){ System.out.println(e.getMessage()); } return results.getMetaData(); } //------------------------------------------------ public String[] getColumnNames(String table) { String[] tbnames = null; Vector tname = new Vector(); try{ results = new resultSet(dma.getTables(catalog,null,table,null)); while (results.hasMoreElements()) tname.addElement(results.getColumnValue("COLUMN_NAME")); } catch(Exception e){ System.out.println(e.getMessage()); } tbnames = new String[tname.size()]; for(int i=0;i<tname.size();i++) tbnames[i] = (String)tname.elementAt(i); return tbnames; } //------------------------------------------------ public void getColumnValue(String table, String columnName) { try{ if (table.length()>0) results = Execute("Select "+columnName+" from "+table+" order by "+columnName); } catch(Exception e){ System.out.println("Erreur sur la valeur de la colonne " +columnName+e.getMessage()); } } //------------------------------------------------ public String getNextValue(String columnName) { String res = ""; try{ if (results.hasMoreElements()) res = results.getColumnvalue(columnName); } catch(Exception e){ System.out.println("Erreur sur la valeur suivante "+columnName+e.getMessage()); } return res; } //------------------------------------------------ public resultSet Execute(String sql) { results = null; try{ Statement stmt = con.createStatement(); results = new resultSet(stmt.executeQuery(sql)); } catch(Exception e){ System.out.println(e.getMessage()); } return results; } } De la même façon, un nouvel objet resultSet (avec un r minuscule) peut être intéressant s'il permet de façon transparente de retourner automatiquement les résultats sous forme d'un tableau de valeurs, ainsi qu'en encapsulant le nombre et le nom des colonnes contenues dans l'objet resultSet...
--
Alain Lompo
Excelta - Conseils et services informatiques
MCT
MCSD For Microsoft .Net
MVP Windows Systems Server / Biztalk Server
Certifié ITIL et Microsoft Biztalk Server
| Cet article est une ébauche concernant l'informatique. Vous pouvez partager vos connaissances en l'améliorant. |
Un objet d'accès aux données (en Anglais Data Access Object ou DAO) est un patron de conception (c'est-à-dire un modèle pour concevoir une solution) utilisé dans les architectures logicielles objet.
Sommaire[masquer] |
Les objets en mémoire vive sont souvent liés à des données persistantes (stockées en base de données, dans des fichiers, dans des annuaires, etc.). Le modèle DAO propose de regrouper les accès aux données persistantes dans des classes à part, plutôt que de les disperser. Il s'agit surtout de ne pas écrire ces accès dans les classes "métier", qui ne seront modifiées que si les règles de gestion métier changent.
Ce modèle complète le vieux modèle "MVC" (Modèle - Vue - Contrôleur), qui préconise de séparer dans des classes différentes les problématiques :
L'utilisation de DAO permet de s'abstraire de la façon dont les données sont stockées au niveau des objets métier. Ainsi, le changement du mode de stockage ne remet pas en cause le reste de l'application. En effet, seules ces classes dites "techniques" seront à modifier (et donc à re-tester). Cette souplesse implique cependant un coût additionnel, dû à une plus grande complexité de mise en œuvre.
Une classe métier :
public class Client implements java.io.Serializable { private String name; ... public void setName(String name) { this.name=name; } public String getName() { return this.name; } ... // méthodes métier public void reglerFacture(noFac){ ... } ... }
Une classe technique :
public class DAOClient implements java.io.Serializable { // Recherche de clients par nom public List<Client> getByName(name) { // accès au fichier ou à la table des clients } // Recherche d'un client par son identifiant public Client getById(id) { ... } // Mise à jour des données d'un client ... } Il est important que cette classe cache complètement d'où viennent les données : elle doit donc renvoyer des objets métier (et non un curseur, un enregistrement, ...).
Une classe contrôleur :
public class GestionnaireClient { /* Objet d'accès aux données */ private DAOClient daoClient; ArrayList listeClients = daoClient.getByName("Untel"); ... } Il peut exister autant de types de DAO que de moyens de persistance des données.
Des bibliothèques logicielles sont d'ailleurs conçues spécifiquement pour prendre en charge ces aspects.