我想简单地从sql server获取数据并在我的java程序中使用它,因为我使用过:sql server 2017,jdk10,mssql-jdbc-6.2.2.jre8.jar。顺便说一句,我是dindn'记得我的sql数据库密码(我的意思是我已经忘记了sql server autentification密码)这就是为什么我使用了integratedSecurity = true并在system32中添加了sqljdbc_auth.dll(我想这对我来说很好)但是出于某种原因,我只是盯着看sql server servicies并在防火墙中为servure连接添加新规则我无法从服务器获取数据,我这样做错误:
java lang classnotfoundexception javax xml bind datatypeconverter
这是我的代码,你知道我该如何解决这个问题?
public void dbConnect(String db_connect_string)
{
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(db_connect_string);
System.out.println("connected");
Statement statement = conn.createStatement();
String queryString = "select * from tab1";
ResultSet rs = statement.executeQuery(queryString);
while (rs.next()) {
System.out.println(rs.getString(1));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
DBConnection connServer = new DBConnection();
connServer.dbConnect("jdbc:sqlserver://localhost:51696;databaseName=test;integratedSecurity=true");
}
答案 0 :(得分:0)
java.xml.bind module and has been deprecated and removed from classpath in java 9
Since javax.xml.bind is sub package of Module java.xml.bind you are getting ClassNotFoundException
solution:-
java.xml is deprecated but not removed from Java 9 you have to run by adding below statement
--add-modules java.xml.bind
if you are using maven or gradle just add the below dependencies
Gradle:-
compile 'javax.xml.bind:jaxb-api:2.3.0'
Maven:-
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>