0

I want to simply get data from sql server and use it inside my java program for this reason i have used:sql server 2017, jdk10, mssql-jdbc-6.2.2.jre8.jar. by the way i dindn' remember my sql database password(i mean i have forgotten sql server autentification password) that's why i have used integratedSecurity=true and add sqljdbc_auth.dll in system32( i guess it works fine for me) but for some reason adter staring sql server servicies and adding new rules in firewall for servure connection i can't get data from server, i gto error like this:

java lang classnotfoundexception javax xml bind datatypeconverter

here is my code , do you have any idea how should i solve this task?

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");

    }
  • 1
    Can you verify that the class `SQLServerDriver` is on your classpath? – Tim Biegeleisen Jun 12 '18 at 05:30
  • You may find this https://stackoverflow.com/questions/47422579/noclassdeffounderror-javax-xml-bind-datatypeconverter-with-sql-server-jdbc as helpful. Since you mentioned that you are using JDK10 and the post brings up similar issue working with JDK9. – piy26 Jun 12 '18 at 05:37

1 Answers1

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>