문제

간단한 그루비 스크립트를 DB에 연결하려고합니다.

암호:

import groovy.sql.Sql
class GroovySqlExample2{
  static void main(String[] args) {
    def sql = Sql.newInstance("jdbc:sqlserver://MYSERVERIP", "uname",
           "pwd", "net.sourceforge.jtds.jdbc.Driver")
    sql.eachRow("select * from word"){ 
      println it.spelling + " ${it.part_of_speech}"
    }
  }
}

C : Groovy-1.6.3 lib 폴더 내부에 JTDS-1.2.3.Jar를 배치했지만 위의 코드는 계속 불평합니다.

java.lang.ClassNotFoundException: net.sourceforge.jtds.jdbc.Driver
도움이 되었습니까?

해결책

c : groovy-1.6.3으로 설정된 groovy_home 환경 변수가 있는지 확인하십시오.

다른 팁

포도와 세트를 사용하십시오 systemClassLoader=true

@Grapes(
    @Grab(group='net.sourceforge.jtds', module='jtds', version='1.3.1')
)
@GrabConfig(systemClassLoader=true)
import groovy.sql.*
// http://jtds.sourceforge.net/faq.html#urlFormat
def sql = Sql.newInstance("jdbc:jtds:sqlserver://MYSERVERIP", "uname",
       "pwd", "net.sourceforge.jtds.jdbc.Driver")
sql.eachRow("select * from word"){ 
  println it.spelling + " ${it.part_of_speech}"
}

JTDS-1.2.2.jar를 다운로드하고 DEF SQL 전에 그루비 스크립트에 아래 줄을 추가하십시오.

this.class.classLoader.rootLoader.addURL( new URL("file:/C:\\jtds-1.2.2.jar"))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top