简体   繁体   English

java.lang.ClassNotFoundException:com / microsoft / sqlserver / jdbc / SQLServerDriver

[英]java.lang.ClassNotFoundException: com/microsoft/sqlserver/jdbc/SQLServerDriver

I am really new to JAVA but need to call a SQL Server function which I have been given access to. 我对JAVA确实很陌生,但需要调用一个我已获得访问权限的SQL Server函数。

I have built a JAVA call into a pl/sql function and am successfully calling it from one of my environments. 我已将Java调用内置到pl / sql函数中,并已从我的环境之一成功调用了它。 When I move to another environment I get the error 当我移到另一个环境时,我得到了错误

ORA-29532: Java call terminated by uncaught Java exception: java.lang.ClassNotFoundException: com/microsoft/sqlserver/jdbc/SQLServerDriver ORA-29532:Java调用因未捕获的Java异常而终止:java.lang.ClassNotFoundException:com / microsoft / sqlserver / jdbc / SQLServerDriver

I have researched this to death and checked the correct installation of JAVA which seems fine but I'm obviously missing something. 我已经对此进行了彻底研究,并检查了JAVA的正确安装,这看起来不错,但我显然缺少某些东西。 I need to somehow trace what is different on this environment, the fact that it runs in the other envionmnet proves that the class is correct so it has to be a config issue. 我需要以某种方式跟踪此环境的差异,它在另一个环境中运行的事实证明了该类是正确的,因此它必须是配置问题。

JAVA Class JAVA类

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.net.Socket;
import java.io.IOException;

public class xxiceHJ
{
    protected static String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  
    protected static String DB_URL = "jdbc:sqlserver://999.999.99.99:1433";
    protected static String USER = "xxxx";
    protected static String PWD = "xxxxx123$";

    public static String getOrderStatus (String OrderNumber) throws SQLException, Exception
    {
        Connection conn = null;
        CallableStatement cs = null;
        ResultSet rs = null;
        String Message = null;
        String WarehouseId = "01";

        try
        { 
            // Register JDBC driver
            Class.forName(JDBC_DRIVER);

            //Open a connection
            conn = DriverManager.getConnection(DB_URL, USER, PWD);

            cs = conn.prepareCall("{call usp_get_order_status(?,?,?)}"); 
            cs.setString(1, WarehouseId);
            cs.setString(2, OrderNumber);
            cs.setString(3, Message);

            rs = cs.executeQuery();

            //if prodeure return a value
            if (rs.next())
            {
                Message = rs.getString(1);
            }

            //Clean-up environment
            rs.close();
            cs.close();
            conn.close();

//        }
//        catch (SQLException se)
//        {
//            //Handle errors for JDBC
//            cfFileNumber = "SQLException" + se.toString();
//            se.printStackTrace();
//        }
//        catch (Exception e)
//        {
//            //Handle errors for Class.forName
//            cfFileNumber = "Exception" + e.toString();
//            e.printStackTrace();
        }
        finally
        {
            //finally block used to close resources
            try
            {
                if (rs!=null)
                {
                    rs.close();
                }
            }
            catch (SQLException se2)
            {
                //nothing we can do
            }
            try
            {
                if (cs!=null)
                {
                    cs.close();
                }
            }
            catch (SQLException se2)
            {
                //nothing we can do
            }
            try
            {
                if (conn!=null)
                {
                    conn.close();
                }
            }
            catch (SQLException se)
            {
                se.printStackTrace();
            }

        }
        return Message;

    }



}

The CLASSPATH variable is the search string that Java Virtual Machine (JVM) uses to locate the JDBC drivers on your computer. CLASSPATH变量是Java虚拟机(JVM)用于在您的计算机上定位JDBC驱动程序的搜索字符串。 If the drivers are not listed in your CLASSPATH variable, you receive the following error message when you try to load the driver: java.lang.ClassNotFoundException: com/microsoft/jdbc/sqlserver/SQLServerDriver 如果驱动程序未在CLASSPATH变量中列出,则在尝试加载驱动程序时会收到以下错误消息:java.lang.ClassNotFoundException:com / microsoft / jdbc / sqlserver / SQLServerDriver

The JDBC driver is not part of the Java SDK. JDBC驱动程序不是Java SDK的一部分。 If you want to use it, you must set the classpath to include the sqljdbc.jar file or the sqljdbc4.jar file. 如果要使用它,则必须将类路径设置为包括sqljdbc.jar文件或sqljdbc4.jar文件。 If the classpath is missing an entry for sqljdbc.jar or sqljdbc4.jar, your application will throw the common "Class not found" exception. 如果类路径缺少sqljdbc.jar或sqljdbc4.jar的条目,则您的应用程序将引发常见的“找不到类”异常。

The sqljdbc.jar file and sqljdbc4.jar file are installed in the following location: \\sqljdbc_\\\\sqljdbc.jar \\sqljdbc_\\\\sqljdbc4.jar sqljdbc.jar文件和sqljdbc4.jar文件安装在以下位置:\\ sqljdbc _ \\\\ sqljdbc.jar \\ sqljdbc _ \\\\ sqljdbc4.jar

The following is an example of the CLASSPATH statement that is used for a Windows application: CLASSPATH =.;C:\\Program Files\\Microsoft JDBC Driver 4.0 for SQL Server\\sqljdbc_4.0\\enu\\sqljdbc.jar 以下是用于Windows应用程序的CLASSPATH语句的示例: CLASSPATH = .; C:\\ Program Files \\ SQL Server的Microsoft JDBC驱动程序4.0 \\ sqljdbc_4.0 \\ enu \\ sqljdbc.jar
The following is an example of the CLASSPATH statement that is used for a Unix/Linux application: CLASSPATH =.:/home/usr1/mssqlserverjdbc/Driver/sqljdbc_4.0/enu/sqljdbc.jar You must make sure that the CLASSPATH statement contains only one Microsoft JDBC Driver for SQL Server, such as either sqljdbc.jar or sqljdbc4.jar. 以下是用于Unix / Linux应用程序的CLASSPATH语句的示例: CLASSPATH =。:/ home / usr1 / mssqlserverjdbc / Driver / sqljdbc_4.0 / enu / sqljdbc.jar您必须确保CLASSPATH语句包含仅一个用于SQL Server的Microsoft JDBC驱动程序,例如sqljdbc.jar或sqljdbc4.jar。

For more information, please see: 有关更多信息,请参见:
http://support.microsoft.com/kb/313100 http://support.microsoft.com/kb/313100
http://msdn.microsoft.com/en-us/library/ms378526.aspx http://msdn.microsoft.com/en-us/library/ms378526.aspx

first Please download correct sql driver and then check your are using correct connection driver as per operating system. 首先,请下载正确的sql驱动程序,然后根据操作系统检查您使用的连接驱动程序是否正确。 then once you have to test your connection if its working fine then you will go to next . 然后,一旦必须测试连接是否正常,则将转到下一步。 so please check this url 所以请检查这个网址
microsift sql server driver for linux https://msdn.microsoft.com/en-us/library/hh568451(v=sql.110).aspx 适用于Linux的microsift sql服务器驱动程序https://msdn.microsoft.com/zh-cn/library/hh568451(v=sql.110).aspx

my sql server driver for linux https://dev.mysql.com/downloads/connector/j/5.0.html 我的Linux版sql服务器驱动程序https://dev.mysql.com/downloads/connector/j/5.0.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver - java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver 从 Java 连接到 SQ 服务器时出错:java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver - Error connecting to SQ Server from Java: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver java.lang.ClassNotFoundException:无法在新的 docker 容器上加载 class:com.microsoft.sqlserver.jdbc.SQLServerDriver - java.lang.ClassNotFoundException: Unable to load class: com.microsoft.sqlserver.jdbc.SQLServerDriver on new docker container java.lang.ClassNotFoundException:创建jar后的com.microsoft.sqlserver.jdbc.SQLServerDriver - java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver after creating a jar java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver找不到javax.net.ssl.SSLSocket - java.lang.ClassNotFoundException: javax.net.ssl.SSLSocket not found by com.microsoft.sqlserver.jdbc.SQLServerDriver 类路径设置,但是:java.lang.ClassNotFoundException:com.microsoft.sqlserver.jdbc.SQLServerDriver - Classpath set, but: java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver java.lang.ClassNotFoundException:com.microsoft.jdbc.sqlserver.SQLServerDriver:我是否正在加载正确的驱动程序? - java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver : Am I loading the right driver? java.lang.ClassNotFoundException:Maven项目中的com.microsoft.sqlserver.jdbc.SQLServerDriver - java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver in Maven project 在命令行上运行 java 时显示错误消息“java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver” - Error message "java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver" is shown when run java on command line java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver despite the fact it is in dependencies of gradle.build file - java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver despite the fact it is in dependencies of gradle.build file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM