Creating Data Access Services - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Creating Data Access Services

Description:

Data Access code in Java heavily relies on JDBC (Java Database Connectivity) ... facies /facies formation_name KONINGSMOOR /formation_name ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 14
Provided by: BenT54
Category:

less

Transcript and Presenter's Notes

Title: Creating Data Access Services


1
Creating Data Access Services
  • Presented by
  • Ashraf Memon
  • Hands-on
  • Ghulam Memon, Longjiang Ding

2
Overview
  • Writing data access service classes in Java
  • Generating service
  • Deploying services with Apache Axis
  • Generating client files and testing them

3
Writing data access service classes in Java
  • Data Access code in Java heavily relies on JDBC
    (Java Database Connectivity)
  • JDBC is a industry standard Java API from Sun
    Microsystems for communicating with almost all
    the database.
  • The driver is usually provided by the database
    company.

4
Writing data access service classes in Java
5
Writing data access service classes in Java
  • Sample Data Access class contains 1 function,
    which reads country data from PGAP database and
    generates XML for it
  • Method signature is
  • public String getData(String countryName)
  • Anatomy of class code follows on next slide
  • For complete source code check c\data\csig05\ws\s
    olutions\database\DBAccess.java

6
Code Anatomy
  • Load JDBC Driver
  • Class.forName("com.mysql.jdbc.Driver")
  • Establish databse conenction
  • Connection connection DriverManager.getConnectio
    n(
  • "jdbcmysql//geon07.sdsc.edu3306/test
    ", "csig", "csig")
  • Create jdbc statement
  • Statement stmt connection.createStatement()
  • Execute SQL query
  • stmt.executeQuery(sql)
  • Get database metadata (schema)
  • ResultSetMetaData rsmd records.getMetaData()
  • int numColumns rsmd.getColumnCount()
  • String columnNames new StringnumColumns1
  • // Get the column names column indices start
    from 1
  • for (int i1 iltnumColumns1 i)
  • columnNamesi rsmd.getColumnName(i)

7
Code Anatomy (contd)
  • Get result data (schema)
  • while (records.next())
  • xml "ltrecordgt\r\n\t\t"
  • for (int i1 iltnumColumns1 i)
  • xml "lt" columnNamesi "gt"
    records.getString(i) "lt/" columnNamesi
    "gt\r\n\t\t"
  • xml "lt/recordgt\r\n\t"

8
Testing the code
  • Navigate to solutions directory
    c\data\csig05\ws\solutions
  • Open command prompt by right clicking on the
    database directory and selecting Command Prompt
    Here
  • Change to database directory by typing following
    at the command prompt
  • cd database
  • Compile DBAccess.java file by typing following at
    command prompt
  • javac DBAccess.java
  • Add mySQL JDBC driver to classpath by typing
    following at the command prompt
  • C\tools\Tomcat4.1\webapps\axis\WEB-INF\classe
    s\classpath.bat
  • Run program by typing following at command prompt
  • java DBAccess
  • Output should be of the form

9
Testing the code (contd)
  • lttablegt
  • ltrecordgt
  • ltcountrygtGERMANYlt/countrygt
  • ltstategtlt/stategt
  • ltarea_codegtlt/area_codegt
  • ltlat_decgt53.2lt/lat_decgt
  • ltlng_decgt9.6lt/lng_decgt
  • ltage_topgt50000lt/age_topgt
  • ltage_botgt50000lt/age_botgt
  • ltbookgtEURlt/bookgt
  • ltplate_codegt703lt/plate_codegt
  • ltpgap_envi1gt5lt/pgap_envi1gt
  • ltpgap_envi2gt5lt/pgap_envi2gt
  • ltfaciesgtlt/faciesgt
  • ltformation_namegtKONINGSMOORlt/formation_namegt
  • ltstrat_reliabilitygtComplete biostratigraphic
    controllt/strat_reliabilitygt
  • ltgeo_reliabilitygtnulllt/geo_reliabilitygt
  • ltinvestigatorgtlt/investigatorgt
  • ltDate_of_Entrygt12-3-92lt/Date_of_Entrygt

10
Deploying your code as a web services with Apache
Axis
  • Copy generated class file to C\tools\tomcat4.1\we
    bapps\axis\WEB-INF\classes\
  • Open using any text editor deployDBAccess.wsdd
    from C\tools\tomcat4.1\webapps\axis\WEB-INF\class
    es\
  • Verify the content so that it matches the current
    service and its corresponding class

11
Deploying services with Apache Axis
  • Type following on command line to navigate to
    C\tools\tomcat4.1\webapps\axis\WEB-INF\classes\
  • cd C\tools\tomcat4.1\webapps\axis\WEB-INF\classe
    s\
  • Execute deployment descriptor by typing
    deploy.bat deployDBAccess.wsdd at command prompt
  • This will deploy database webservice on Axis SOAP
    Server
  • Test it by going to http//localhost/axis/ and
    navigating to DBAccessService

12
Generating client files and testing them
  • Change directory to c\data\csig05\ws\solutions\da
    tabase by typing cd c\data\csig05\ws\solutions\d
    atabase on the command prompt
  • Compile DBAccessServiceClient.java by typing
    following at command prompt
  • javac DBAccessServiceClient.java
  • Execute Client by typing following at command
    prompt
  • java DBAccessServiceClient
  • Output should be similar to previous one.

13
Next Chapter
  • Creating Web Service to access functionality of a
    tool
Write a Comment
User Comments (0)
About PowerShow.com