2014-10-11 3 views

답변

2

응용 프로그램에 가장 기본적인 설치는 매우 쉽습니다. 정말로 라이브러리/항아리를 클래스 경로에 배치하는 것입니다. Netbeans에는 이미이 라이브러리가 함께 제공되므로 다운로드 할 필요가 없습니다. 어떤 이유인지 모르면 here에서 다운로드 할 수 있습니다. 압축을 푼 후 derby.jar (및 필요한 경우 다른 사람)을 클래스 경로에 추가하기 만하면됩니다.

기본적으로 Netbeans의 프로젝트에서 [라이브러리]를 마우스 오른쪽 버튼으로 클릭하고 [라이브러리 추가]를 선택하십시오.

enter image description here

그런 다음 당신이 다음 대신 [라이브러리 추가]의 라이브러리를 다운로드 한 경우 [항아리 추가]를 선택하고 [자바 DB] 라이브러리

enter image description here

을 선택하고 검색 당신이 그것을 다운로드 한 항아리.

그런 다음 응용 프로그램에서 데이터베이스를 사용할 수있는 넷빈즈 라이브러리

enter image description here

와 함께 제공되는 항아리입니다. 임베디드 버전은 애플리케이션과 동일한 JVM에서 실행되기 때문에 직접 데이터베이스 시작 및 종료를 처리해야 할 수 있습니다. 다음은 시작되는 예제 응용 프로그램입니다 - createsdb-inserts-select-shutsdown. 우리가 그것을 만들 때

import java.sql.*; 

public class DerbyProject { 
    public static void main(String[] args) throws Exception { 
     /* ------- Start DB ----------- */ 
     final String driver = "org.apache.derby.jdbc.EmbeddedDriver"; 
     Class.forName(driver).newInstance(); 

     final String protocol = "jdbc:derby:"; 
     final String dbName = "derbyDB"; 
     Connection connection = DriverManager.getConnection(
       protocol + dbName + ";create=true"); 
     System.out.println("===== Started/Connected DB ====="); 

     /* 
     * Drop table for testing. If we don't drop, running the 
     * same program will fail, if we start our application over 
     * as the new table has been persisted 
     */ 
     final String dropSql = "drop table users"; 
     Statement statement = connection.createStatement(); 
     try { 
      statement.execute(dropSql); 
      System.out.println("===== Dropped Table 'users' ====="); 
     } catch (SQLException e) { 
      if (!e.getSQLState().equals("42Y55")) { 
       throw e; 
      } 
     } 

     /* ----- Creeate 'users' table ----- */ 
     final String createSql = "create table users (id int, name varchar(32))"; 
     statement.execute(createSql); 
     System.out.println("===== Created Table 'users' ====="); 

     /* ----- Insert 'peeskillet' into 'users' ----*/ 
     final String insertSql = "insert into users values (1 , 'peeskillet')"; 
     statement.execute(insertSql); 
     System.out.println("===== inserted 'peeskillet into 'users' ====="); 

     /* ----- Select from 'users' table ----- */ 
     final String selectSql = "select name from users where id = 1"; 
     ResultSet rs = statement.executeQuery(selectSql); 
     if (rs.next()) { 
      System.out.println("===== Selected from 'users' with id 1 \n" 
        + "\t\t\t result: " + rs.getString("name") + " ====="); 
     } 

     /* ------ Shut Down DB ------- */ 
     try { 
      DriverManager.getConnection("jdbc:derby:;shutdown=true"); 
     } catch (SQLException se) { 
      if (((se.getErrorCode() == 50000) 
        && ("XJ015".equals(se.getSQLState())))) { 
       System.out.println("Derby shut down normally"); 
      } else { 
       System.err.println("Derby did not shut down normally"); 
       throw se; 
      } 
     } 

     statement.close(); 
     rs.close(); 
     connection.close(); 
    } 
} 

, 넷빈즈의 기본 빌드는 dist\lib에 항아리를 넣고 MANIFEST.MF의 클래스 경로에 그 항아리를 넣어해야합니다. 당신은 당신이 파일이 넷빈즈에서 볼 열 경우 데이터가 실제로 저장되는 위치, 당신이 볼 수있는 그

enter image description here

을 테스트하기 위해 명령 줄에서 항아리를 실행할 수 있습니다.

: 더비 더비 튜토리얼에 대한 자세한 내용은

enter image description here


관련 문제