티스토리 뷰

GAS(Google Apps Scripts)에서는 JDBC를 이용해서 서버의 자료를 불러 올 수 있다.

방법은 2가지정도 찾아 내었고 장단점이 있다.

 

우선 이 작업은 SQL을 어느정도 알고 있다는 전제 조건하에 출발한다.

아래는 class를 이용한 예제 이다.

prepareStatement로 하는 방법이 있다. 그리고 또 다른방법은 Statement객체를 이용하는 방법이 있다.

아래 예제는 PrepareStatement를 이용한 방법이다.

class DatabaseSelect {
  constructor(){
    Logger.log('make constructor');
    this.svrName = '서버주소:포트';
    this.usr = '계정';
    this.pw = '비밀번호';
    this.databaseName = '데이터베이스이름';
    this.instanceUrl = 'jdbc:mysql://' + this.svrName;
    this.databaseUrl = this.instanceUrl + '/' + this.databaseName;    
    
  }
  //검증 메소드생성
  selectItem(poNumber,styleCode){
    let conn = Jdbc.getConnection(this.databaseUrl, this.usr, this.pw);
    let pstmt = conn.prepareStatement("SELECT * FROM 테이블명 WHERE `필드명` = ?");
    
    pstmt.setString(1, ?에 넣는 값을 여기에넣음);    
    let rs = pstmt.executeQuery();
    let temp = rs.next();

    rs.close();
    pstmt.close();
    conn.close();
    return temp;
  }

'프로그래밍 학습 > Google Apps Scripts' 카테고리의 다른 글

Google Apps Scripts에 대하여.  (0) 2022.07.07
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함