Db Server Sources

Embed Size (px)

Citation preview

  • 7/27/2019 Db Server Sources

    1/6

    Creating Database Server Types and Data Sources

    April 2006[Revision number: V2.1-1]Copyright 2006 Sun Microsystems, Inc.

    This tutorial walks you through the process of adding a database server type and a data source in the Sun Java StudioCreator integrated development environment (the IDE). You enable the IDE to use database software for which theIDE does not already have drivers. You also add a database to be used as a data source by your applications.

    Contents

    - About Database Servers

    - Creating a Database Server Type

    - Creating a Data Source

    About Database Servers

    To create a database connection from the IDE, you must use a driver that is registered in the IDE and a driver thatsupports the JDBC API (the JDBC driver) 3.0. This tutorial uses the MySQL driver, but you can use any JDBC 3.0compliant driver.

    The following servers are registered when you install the IDE:

    q IBM DB2q Oracleq Bundled Databaseq Microsoft SQL Serverq Sybase

    If you already use one of these registered database servers, go to the Creating a Data Source section of this tutorial.

    Creating a Database Server Type

    To add a database server type to the IDE, download the appropriate JDBC driver and install it if needed. Ensure that thedatabase server is runningwhile adding a data source for this server type, you attempt to connect to the databaseserver.To add MySQL as a registered driver in the IDE, follow these steps.

    1. Download the MySQL JDBC driver.

    You need at least version 3.1.11 of the JDBC driver.2. Extract the files into a folder on your system.

    Note: Do not use spaces in your folder path name.

    3. In the Servers window in the IDE, right-click Data Sources and choose Edit Database Server Types from the pop-up menu, as shown in the following figure.

    1

    http://dev.mysql.com/downloads/connector/j/3.1.htmlhttp://dev.mysql.com/downloads/connector/j/3.1.html
  • 7/27/2019 Db Server Sources

    2/6

    Figure 1: Edit Database Server Types

    4. Click New in the Edit Database Server Types dialog box.

    5. Navigate to the directory into which you extracted the MySQL JDBC driver.

    6. Select the mysql-connector-java-driverversion-bin.jar file and click Open.

    The IDE creates a database server type named ServerType1.7. Rename the database server type by entering MySQL in the Display Name text field.

    8. Consult your JDBC vendor documentation for the correct JDBC driver class name and database URL template.Click Suggest to get the possible driver classes and the URL template for the specified JDBC driver JAR files.

    r Driver Class Name. For MySQL, the suggested driver class is org.gjt.mm.mysql.Driver orcom.mysql.jdbc.Driver (see Figure 2). If you click the Suggest button, and your database serverhas multiple driver classes available, select the appropriate driver in the Driver Class Name box. Somesuggested driver names might not work, so you might need to try more than one.

    r URL Template. The suggested URL template for MySQL is jdbc:mysql://#HOSTNAME/#DATABASE (see Figure 2). #HOSTNAME and #DATABASE are IDE-specific parameters. When youcreate a data source using this database server type, the IDE automatically replaces #HOSTNAME and#DATABASE with the host name and database name that you provide, which is described in thefollowing section.

    2

  • 7/27/2019 Db Server Sources

    3/6

    Figure 2: Completed Edit Database Server Types screen

    9. Click Close to create the database server type and close the dialog box.

    Creating a Data Source

    To add a database to be used as a data source by your application, follow these steps: .

    1. In the Servers window, right-click Data Sources and choose Add Data Source from the pop-up menu.

    2. In the Add Data Source dialog box, choose a server type from the Server Type drop-down list, then set thevalues appropriate to your installation in the Data Source Name, Database Name, Host Name, User ID,Password, and Validation Table fields.

    This tutorial's MySQL example uses the values shown in the following dialog box. Note the Database URL. Theparameters #HOSTNAME and #DATABASE that you entered when you created the server type are automaticallyreplaced by the Database Name and Host Name provided in this dialog box.

    3

  • 7/27/2019 Db Server Sources

    4/6

    Figure 3: Completed Add Data Source Dialog BoxNote; If you are adding a data source for the Microsoft SQL server driver, and you want Windowsauthentication, leave the User ID and Password fields blank. The driver automatically uses the Windows user idand password to make a connection to the database. For more information, see The Microsoft SQL ServerDriver.

    3. Click Test Connection to ensure that the IDE can connect to your database.

    If you get an error message, verify that the information in the text fields is correct for your database, and ensurethat your database server is running. If the error dialog box displays the message Invalidauthorization specification, message from server: "Access denied for user:

    'user'@'localhost' (Using password:YES)", ensure that 'user' is granted permission on thedatabase server to access the database from localhost.

    You may need to create a validation table for testing purposes. When your application runs, it obtains databaseconnections from a Sun Java System Application Server connection pool. The application server validates theconnection by querying the validation table. The table must exist and be accessible, but it does not require anyrows. Do not use an existing table that has a large number of rows or a table that is already frequently accessed.See your database vendor's documentation for more information.

    4. Click Add to add the data source.

    Summary

    The process of creating a data source for a new database consists of two steps:

    1. Define a new database server type, in which the URL may reference the parameters #HOSTNAME and#DATABASE.

    2. Create a new data source, which instantiates one of the database server types.

    4

    http://media.datadirect.com/download/docs/jdbc/jdbcref/jdbcsqlsrv.html#wp962753_http://media.datadirect.com/download/docs/jdbc/jdbcref/jdbcsqlsrv.html#wp962753_http://media.datadirect.com/download/docs/jdbc/jdbcref/jdbcsqlsrv.html#wp962753_http://media.datadirect.com/download/docs/jdbc/jdbcref/jdbcsqlsrv.html#wp962753_
  • 7/27/2019 Db Server Sources

    5/6

    q Using Databound Components to Access Databasesq System Requirements lists the supported databasesq MySQL Documentation

    More Developer Resources:For more tutorials, articles, tips, forums, updates, and expert advice for developers, visit the Java Studio Creatordeveloper resources on the Sun Developer Network (SDN) at http://developers.sun.com/jscreator/.

    This page was last modified: September 12, 2006

    Sun and Third-party Trademarked Terminology

    The following Sun trademarked terms might be used in the Sun Java(tm) Studio Creator tutorials:

    q Sun Java Studio Creator integrated development environment (IDE)q Sun Java System Application Server version number(Application Server)q Java Platform, Standard Edition technology (Java SE(tm) platform)q JavaServer(tm) Faces technologyq JavaServer Pages(tm) technology (JSP(tm) technology)q Sun Java System Web Server version number(Web Server)q Java Database Connectivity software (JDBC software)q Enterprise JavaBeans(tm) specification (EJB(tm) specification)q Solaris(tm) Operating System software (Solaris OS software)

    The following third-party trademarked terms might be used in the Sun Java Studio Creator tutorials:

    q UNIX(R) softwareq SPARC(R) processor

    Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rightsreserved.

    Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described inthis document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S.patents listed at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S.and in other countries.

    U.S. Government Rights - Commercial software.

    Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of theFAR and its supplements. Use is subject to license terms. Sun, Sun Microsystems, the Sun logo, Java and the Java CoffeeCup logo are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.This product iscovered and controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries.Nuclear, missile, chemical biological weapons or nuclear maritime end uses or end users, whether direct or indirect, arestrictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusionlists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited.

    Note: Sun is not responsible for the availability of third-party web sites mentioned in this document and does not endorseand is not responsible or liable for any content, advertising, products, or other materials on or available from such sites orresources. Sun will not be responsible or liable for any damage or loss caused or alleged to be caused by or in connectionwith use of or reliance on any such content, goods, or services available on or through any such sites or resources.

    See Also:

    5

    http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/databoundcomponents.htmlhttp://developers.sun.com/prodtech/javatools/jscreator/features/sysreqs/index.htmlhttp://dev.mysql.com/doc/http://developers.sun.com/jscreatorhttp://developers.sun.com/jscreatorhttp://developers.sun.com/jscreatorhttp://developers.sun.com/jscreatorhttp://dev.mysql.com/doc/http://developers.sun.com/prodtech/javatools/jscreator/features/sysreqs/index.htmlhttp://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/databoundcomponents.html
  • 7/27/2019 Db Server Sources

    6/6

    Copyright 2006 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, tats-Unis. Tous droitsrservs.

    Sun Microsystems, Inc. dtient les droits de proprit intellectuels relatifs la technologie incorpore dans le produit quiest dcrit dans ce document. En particulier, et ce sans limitation, ces droits de proprit intellectuelle peuvent inclure un ouplus des brevets amricains lists l'adresse http://www.sun.com/patents et un ou les brevets supplmentaires ou lesapplications de brevet en attente aux tats-Unis et dans les autres pays. L'utilisation est soumise aux termes de la Licence.Sun, Sun Microsystems, le logo Sun, Java et le logo Java Coffee Cup sont des marques de fabrique ou des marquesdposes de Sun Microsystems, Inc. aux tats-Unis et dans d'autres pays.Ce produit est soumis la lgislation amricaineen matire de contrle des exportations et peut tre soumis la rglementation en vigueur dans d'autres pays dans ledomaine des exportations et importations. Les utilisations, ou utilisateurs finaux, pour des armes nuclaires,des missiles,des armes biologiques et chimiques ou du nuclaire maritime, directement ou indirectement, sont strictement interdites. Lesexportations ou rexportations vers les pays sous embargo amricain, ou vers des entits figurant sur les listes d'exclusiond'exportation amricaines, y compris, mais de manire non exhaustive, la liste de personnes qui font objet d'un ordre de nepas participer, d'une faon directe ou indirecte, aux exportations des produits ou des services qui sont rgis par lalgislation amricaine en matire de contrle des exportations et la liste de ressortissants spcifiquement dsigns, sontrigoureusement interdites.

    Sun Microsystems n'est pas responsable de la disponibilit de tiers emplacements d'enchanement mentionns dans cedocument et n'approuve pas et n'est pas responsable ou iresponsable d'aucun contenu, de la publicit, de produits, oud'autres matriaux dessus ou fournis par de tels emplacements ou ressources. Sun ne sera pas responsable ou iresponsabled'aucuns dommages ou perte causs ou allgus pour tre caus par ou en liaison avec l'utilisation de ce produit ou laconfiance dans des tels contenu, marchandises, ou services disponibles sur ou par des tels emplacements ou ressources.

    6