JethroJDBC DriverManager.getConnection在使用Dependencies.jar运行Maven Snapshot时抛出NullPointerException

时间:2018-03-29 20:23:56

标签: eclipse maven jethro

当我在Eclipse IDE中本地运行程序时,JethroJDBC DriverManager.getConnection工作正常,但是在使用 Dependencies.jar 运行Maven Snapshot时,同样的代码抛出NullPointerException。在可执行jar中,我可以看到 com.jethrodata 包中存在这些类。 请帮帮我。

HOST="jdbc:JethroData://UATSERVERHOST:9111/UATINSTANCE"

USER= "USERNAME"

PASS= "PassWord"

源码:

public Connection getConnection(String HOST, String USER, String PASS) throws IOException
{
    Connection connection = null;
    try {
        Class.forName("com.jethrodata.JethroDriver");
        //STEP 3: Open a connection
        connection = DriverManager.getConnection(HOST, USER, PASS);
        return connection;
    }
   catch(Exception e) {
        TestAutomationOutput.outputLog("There is an exception in connecting to the jethro database \r\n"+e);
        e.printStackTrace();
    }      
    return null;
}

的pom.xml:

<dependency>
    <groupId>com.jethro</groupId>
    <artifactId>jethrojdbc</artifactId>
    <version>3.8</version>
</dependency>

  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
     </plugin>   
     <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/lib
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
      </plugin>
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.2</version>
            <configuration>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                        <mainClass>rdltestmodule.RDLAutomationFrame</mainClass>
                    </manifest>
                </archive>
            </configuration>
      </plugin>  
      <plugin>      
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-5</version>   
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>rdltestmodule.RDLAutomationFrame</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
          </execution>
        </executions>   
      </plugin>
    </plugins>
  </build>

异常:

java.sql.SQLException: java.lang.NullPointerException
        at com.jethrodata.JethroDriver.connect(JethroDriver.java:115)
        at com.jethrodata.JethroDriver.connect(JethroDriver.java:16)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at java.sql.DriverManager.getConnection(Unknown Source)
        at rdltestmodule.JethroConnection.getConnection(JethroConnection.java:36)
        at rdltestmodule.TestManager.MasterTest(TestManager.java:39)
        at rdltestmodule.RDLAutomationFrame$2.actionPerformed(RDLAutomationFrame.java:253)
        at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
        at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
        at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
        at java.awt.Component.processMouseEvent(Unknown Source)
        at javax.swing.JComponent.processMouseEvent(Unknown Source)
        at java.awt.Component.processEvent(Unknown Source)
        at java.awt.Container.processEvent(Unknown Source)
        at java.awt.Component.dispatchEventImpl(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
        at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
        at java.awt.Container.dispatchEventImpl(Unknown Source)
        at java.awt.Window.dispatchEventImpl(Unknown Source)
        at java.awt.Component.dispatchEvent(Unknown Source)
        at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
        at java.awt.EventQueue.access$500(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.awt.EventQueue$3.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.awt.EventQueue$4.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
        at java.awt.EventQueue.dispatchEvent(Unknown Source)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
        at java.awt.EventDispatchThread.run(Unknown Source)

1 个答案:

答案 0 :(得分:1)

https://jethro.io/driver-downloads 您可以下载jethro jar并将其粘贴到您的项目中,并提供如下所示的依赖

<dependency>
            <groupId>com.jethrodata</groupId>
            <artifactId>jethro-jdbc</artifactId>
            <version>3.8</version>
            <systemPath>${basedir}\src\main\resources\lib\jethro-jdbc-3.8.jar</systemPath>
            <scope>system</scope>
        </dependency> 

您可以使用JethroConnection类进行下面的检查

 JethroConnection connection = null;
    try {
                Class.forName("com.jethrodata.JethroDriver");
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            try {
                connection = ((JethroConnection) DriverManager
                        .getConnection(url, username, password));
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        JethroStatement stmt = null;
        JethroResultSet rs = null;
        stmt = (JethroStatement) connection.createStatement();