Download Getting Started with SAP Sybase ASE 15.7 and Eclipse IDE

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
Getting Started with SAP Sybase
ASE 15.7 and Eclipse IDE and Java
Applies to:
Sybase Adaptive Server Enterprise (ASE) 15.7 Database
Summary
This document is a step-by-step guide aimed at Java developers demonstrating how to get started with
Sybase ASE database using popular open source Eclipse IDE and Java programming language. Document
contains screenshot, code snippets using sample database bundled with ASE database.
Author:
Steve Radman
Company: Sybase, an SAP Company
Created on: 16 October 2012
Author Bio
Steve Radman is Senior Staff Engineer at SAP, Database and Technology Group. He possess extensive
software engineering experience with SAP Sybase Adaptive Enterprise
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
1
Error! No text of specified style in document.
Table of Contents
Overview ............................................................................................................................................................. 3
Setup Eclipse Project Settings............................................................................................................................ 3
Java Code and Sybase ASE database driver use ............................................................................................. 6
Related Content ................................................................................................................................................ 11
Copyright........................................................................................................................................................... 12
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
2
Error! No text of specified style in document.
Overview
This document is a step-by-step guide demonstrating how to create a simple Sybase ASE 15.7 JDBC
Application in the Eclipse IDE using samples database “pubs3” bundled with ASE database.
It is assumed that the reader is familiar with Eclipse and Java development.
The steps and accompanying screenshots are based on the Juno Release (Build 20120614-1722) of the
Eclipse Java EE IDE for Web Developers.
ASE 15.7 includes jConnect 7.0 which is Sybase’s new JDBC Type 4 driver which is huge simplification over
previous JDBC drivers.
More information about pubs3 included samples database can be found here
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc32300.1502/html/sqlug/X27680.
htm
Setup Eclipse Project Settings
Before we can start coding, here are preliminary steps to setup Eclipse IDE
From Eclipse, open the wizard for a New Java Project. Call the project “jConnectASE15_7” and click the
“Next” button.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
3
Error! No text of specified style in document.
In the next “Java Settings” dialog, Select the “Libraries” tab and click the “Add External JARs…” button on
the right-hand side of the dialog. In the file dialog Browse to the Sybase install location (%SYBASE% on
Windows and $SYBASE on Unix systems) and Open “jConnect-7_0\classes\jconn4.jar. Note that jconn4.jar
is the new JDBC 4 compatible JDBC driver for Sybase while the older jconn3.jar driver requires the extra
JDBC 3 boilerplate code (Class.forName() and DriverManager.registerDriver()). After adding jconn4.jar as an
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
4
Error! No text of specified style in document.
External JAR we can click the “Finish” button. With initial setup steps out of way, We are now ready to start
coding.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
5
Error! No text of specified style in document.
Java Code and Sybase ASE database driver use
From the Eclipse menu select “File” | “New” | “Class” and name the class “ConnectAndQuery”.
Ignore the warning “The use of the default package is discouraged” and click “Finish”.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
6
Error! No text of specified style in document.
Now, start editing ConnectAndQuery.java and add the “java.sql.*” import for JDBC
JDBC URL for Sybase database is in format of
jdbc:sybase:Tds:${hostname}:{port}/${databasename}
In our case, hostname =localhost, port=5000 and database name is default bundled with ASE samples
“pubs3”. Hence, complete URL would be
Jdbc:sybase:Tds:localhost:5000/pubs3
If “pubs3” is left off it will connect to the default database setup for the user (often “master”).
ASE Installation doesn’t come with “localhost” as default server name for developer installation.
To make sure that hostname is indeed “localhost” , one would need to modify Sybase interface file sql.ini
located at %SYBASE%\ini\sql.ini on Windows installation. Add a second “master” line for for the server that
specifies “localhost” rather than the specific hostname that is configured by default.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
7
Error! No text of specified style in document.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
8
Error! No text of specified style in document.
[sybase_ase_157]
master=NLWNSCK,localhost,5000
master=NLWNSCK,YKFN00528265A,5000
query=NLWNSCK,YKFN00528265A,5000
This is minimum code required to connect to ASE 15.7 and will run without error if:
1. ASE server is running
2. %SYBASE%\ini\sql.ini is modified to add a “master” with “localhost”
3. One has installed the Pubs3 sample during your ASE installation
4.
ASE server is configured with the default “sa” login with an empty “” password, if not, then enter
appropriate password
If one of the previous four requirements is not met then running the simple sample above will result in an
Exception such as “JZ00L: Login failed” or “Connection refused”. If it succeeds the application will terminate
without any errors or messages. You can modify your sample to change the hostname, the port, the SQL
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
9
Error! No text of specified style in document.
statement, change/remove the database name (“/pubs3” in the example), and modify the username and/or
password.
We will now add code to our sample to query the “authors” table in the “pubs3” database.
Running the project with the new query code will output the first name and last name of the authors to the
Console as shown in the previous screenshot.
Using Sybase jConnect 7.0 to connect to a Sybase ASE 15.7 database is a very simple process in Eclipse.
The amount of boilerplate code required in JDBC 4 is reduced and allows for cleaner code as shown in the
sample demonstrated.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
10
Error! No text of specified style in document.
Related Content
Sybase ASE Developer Edition Download Reference 1
SAP Sybase ASE Developer Center Reference 2
Complete Sybase JDBC Driver Programming Guide Reference 3
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
11
Error! No text of specified style in document.
Copyright
© Copyright 2012 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG.
The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9,
iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server,
PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes,
BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX,
Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems
Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of
Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts
Institute of Technology.
Java is a registered trademark of Oracle Corporation.
JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned
herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and
other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company.
All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document
serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP
Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or
omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the
express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an
additional warranty.
SAP COMMUNITY NETWORK
© 2012 SAP AG
scn.sap.com
12