找不到适用于 jdbc:jtds 的驱动程序

发布于 2025-01-21 03:33:34 字数 4024 浏览 1 评论 0原文

我被一个简单的 java netbeans-maven 项目困住了。

我的程序需要将一些数据写回 SQL Server 数据库。如果我直接从 NetBeans 运行该程序,则操作可以成功,它按我的预期工作。

但是,如果我构建 JAR 文件,然后从开发环境外部运行,则插入 SQL 序列总是会返回异常(我使用普通 jdbc 驱动程序进行查询的程序的其余部分工作正常):

异常是:

找不到jdbc的合适驱动程序:jtds:sqlserver://server:1433;user=user;password=password;integratedSecurity=true;encrypt=true;trustServerCertificate=true;ssl=require;

我尝试将 sqljdbc_auth.dll 添加到 Sys32 中,并再次构建所有依赖项,并将 jtds 驱动程序添加到 Windows 类路径中,但没有任何运气。

您能否为我添加一些类型的指导/帮助,如何在没有开发环境的情况下消除问题并正确运行代码? 谢谢

这是 pom xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Group</groupId>
    <artifactId>ContainerArrival</artifactId>
    <version>0.9</version>
    <packaging>jar</packaging>   
      <build>
    <plugins>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <transformers>
                    <transformer implementation=
                      "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>something.ContainerArrivalFrame</mainClass>
                </transformer>
            </transformers>
                <filters>
        <filter>
            <artifact>*:*</artifact>
            <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
            </excludes>
        </filter>
    </filters>
        </configuration>
        </execution>
    </executions>
</plugin>
    </plugins>
  </build>

    <dependencies>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.4.1.jre8</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
</project>

I am stuck with a simple java netbeans-maven project.

My program need to write back some data into SQL Server database. The operation can be successfully if I run the program from NetBeans directly, it works as I expected.

But if I build the JAR file then run from outside of the dev environment the insert SQL sequence always get exception back (the rest of the program where I use normal jdbc driver for querying works properly):

The exception is:

No suitable driver found for jdbc:jtds:sqlserver://server:1433;user=user;password=password;integratedSecurity=true;encrypt=true;trustServerCertificate=true;ssl=require;

I tried to add the sqljdbc_auth.dll into Sys32, and build all the dependencies again, and add the jtds driver into windows classpath, without any luck.

Can you add me some type of guidance/help how the problem can be eliminate and run the code properly without the dev environment?
Thanks

Here is the pom xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Group</groupId>
    <artifactId>ContainerArrival</artifactId>
    <version>0.9</version>
    <packaging>jar</packaging>   
      <build>
    <plugins>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
        <execution>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <shadedArtifactAttached>true</shadedArtifactAttached>
                <transformers>
                    <transformer implementation=
                      "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>something.ContainerArrivalFrame</mainClass>
                </transformer>
            </transformers>
                <filters>
        <filter>
            <artifact>*:*</artifact>
            <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
            </excludes>
        </filter>
    </filters>
        </configuration>
        </execution>
    </executions>
</plugin>
    </plugins>
  </build>

    <dependencies>
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>mssql-jdbc</artifactId>
            <version>8.4.1.jre8</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>
<dependency>
    <groupId>jakarta.xml.bind</groupId>
    <artifactId>jakarta.xml.bind-api</artifactId>
    <version>2.3.2</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
</project>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄凉少年不暖心 2025-01-28 03:33:34

谢谢所有的帮助,我找到了这个问题,现在看起来有效。问题是class.forname(“ net.sourceforge.jtds.jdbc.driver”);方法未正确定义。

Thanks all the help, I found the issue and It looks works for now. The issue was that the Class.forName("net.sourceforge.jtds.jdbc.Driver"); method was not defined properly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文