问题描述
我刚从这里安装了JDBC驱动程序,用于Sql Server(http://www.microsoft.com/en-us/download/details.aspx?id=11774),我测试了此示例代码来测试连接:
我收到的错误似乎在行:
Class.forName(com.microsoft.sqlserver.jdbc.SQLServerDriver);
java.lang.ClassNotFoundException:
com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader $ 1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
在java.lang.ClassLoader.loadClass(未知来源)
at sun.misc.Launcher $ AppClassLoader.loadClass(Unknown Source)
在java.lang.ClassLoader.loadClass(未知来源)
在java.lang.Class.forName0(本机方法)
两个注释:
- 如果我删除try-finally代码,我会得到NO错误==>其中可能会证明用户&密码我创建为数据库的登录信息。
- 我创建了一个Person表,联系人作为我的数据库中的列。
侧面问题:
- 这是什么意思:localhost:1433
- 如何设置Eclipse来显示什么行触发错误?非常感谢!
主要问题:
您是否将sqljdbc4.jar文件添加到类路径?如果没有,java不知道在哪里找到类。
- 旁边的问题:
localhost是指你的电脑,意思是你尝试连接到运行程序的计算机上安装的sql server。
通过您的网络适配器解决您自己的ip。冒号(:)后面的数字是端口号。在计算机(或任何其他网络设备)上,可以有多个应用程序通过网络发送和接收数据。其应用程序在特定端口上侦听数据。而SQL Server的标准端口是1443
-
旁边的问题:
使用
尝试{
可以抛出异常的代码
} catch(HandledException e){
e.printStacktrace();
}
在控制台上打印有关异常的信息。
I just installed the JDBC driver from here for Sql Server (http://www.microsoft.com/en-us/download/details.aspx?id=11774) and I tested this sample code to test the connection:
http://msdn.microsoft.com/en-us/library/aa342339.aspx
The error I get seems to be in line:
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
java.lang.ClassNotFoundException:
com.microsoft.sqlserver.jdbc.SQLServerDriver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
Two notes:
- If I remove the try-finally code I get NO error ==> which probably prooves there is nothing wrong with the user & password I created as login information to the database.
- I created a Person table with Contact as a column in my database.
Side questions:
- What exactly does this mean: localhost:1433
- How can I set Eclipse to show me what line triggers the error? Thank you very much!
Main question:
Did you add the sqljdbc4.jar file to your class path? If not, java does not know where to find the classes.
- side question:localhost refers to your computer, meaning you try to connect to a sql server, that is installed on the computer you run the programm on.
gets resolved by your network adapter to your own ip. The number behind the colon(:) is the port number. On a computer (or any other network device for that matter) there can be multiple applications sending and receiving data over the network. An application therefor listens on a specific port for data. And the standard port for SQL server is 1443
side question:use
try{code that can throw exceptions}catch(HandledException e){e.printStacktrace();}
to print information about the exception on your console.
这篇关于JDBC连接失败(java.lang.ClassNotFoundException)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!