database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
DB2
ㆍCache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Cache Q&A 379 게시물 읽기
No. 379
가장 간단한 Java 어플리케이션 예제
작성자
POSTRDBCOKR
작성일
2009-03-26 17:55ⓒ
2009-03-26 18:01ⓜ
조회수
5,400

이 예제는 Cache(혹은 Ensemble) 설치 이후 <CACHE디렉터리>/Dev/Java/Samples 에 SampleApplication.java로 추가되어 있습니다.
실행해 보려면 아래와 같이 입력합니다.
> Java SampleApplcation

팁으로 종종 설치하다가 NoClassDefFoundError를 만나는 경우가 있습니다. 이럴 때는 <CACHE디렉터리>/Dev/Java/Javavar.bat 명령을 수행하고 나서 다시 실행해 보면 될 겁니다. 원인은 CLASSPATH 설정 때문에 생기는 오류로서 다음과 같은 CLASSPATH를 추가해 주는 역할을 합니다: set CLASSPATH=.;c:\InterSystems\Cache\Dev\Java\lib\JDK16\CacheDB.jar

/*
 * SampleApplication.java
 *
 */

import com.intersys.objects.CacheDatabase;
import com.intersys.objects.Database;
import com.intersys.objects.Id;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class SampleApplication
{
    public static void main (String[] args)
    {

 Database dbconnection = null;
        String url = "jdbc:Cache://localhost:1972/SAMPLES";
        String username = "_SYSTEM";
        String password = "SYS";
        Sample.Person person = null;

        try
            {
                // Connect to Cache on the local machine,
                // in the SAMPLES namespace
                dbconnection =
                    CacheDatabase.getDatabase (url, username, password);

                // Open an instance of Sample.Person,
                // whose ID is read in from the console
                InputStreamReader isr = new InputStreamReader (System.in);
                BufferedReader br = new BufferedReader (isr);
                System.out.print ("Enter ID of Person object to be opened:");
                String strID = br.readLine ();

                // Use the entered strID as an Id and use that Id to
                // to open a Person object with the _open() method inherited
                // from the Persistent class. Since the _open() method returns
                // an instance of Persistent, narrow it to a Person by casting.
                person =
                    (Sample.Person) Sample.Person.open (dbconnection,
                        new Id (strID));

                // Fetch some properties of this object
                System.out.println ("Name: " + person.getName ());
                System.out.println ("City: " + person.getHome ().getCity ());

                // Modify some properties
                person.getHome ().setCity ("Ulan Bator");

                // Save the object to the database
                person.save ();

                // Report the new residence of this person */
                System.out.println ("New City: " + person.getHome ().getCity ());

                /* de-assign the person object */
                dbconnection.closeObject (person.getOref ());
                person = null;

                // Close the connection
                dbconnection.close ();

            }

[Top]
No.
제목
작성자
작성일
조회
382[SQL,COS] CEIL 함수 만들기 [1]
POSTRDB
2009-03-30
5676
381[설치] RedHat에서 Shared Memory 늘리기
POSTRDBCOKR
2009-03-26
5841
380[COS] LPAD함수 만들기
POSTRDBCOKR
2009-03-26
4926
379가장 간단한 Java 어플리케이션 예제
POSTRDBCOKR
2009-03-26
5400
378일본어 가능 개발자
InterSystems
2009-03-26
5399
377[Zen] Chart 가운데로 정렬하기
구글그룹스
2009-03-18
5594
376[Zen] Tab에 Zen Page 삽입
구글그룹스
2009-03-18
5826
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2023 DSN, All rights reserved.
작업시간: 0.066초, 이곳 서비스는
	PostgreSQL v16.1로 자료를 관리합니다