0

For some reason, my application will not connect and I am unsure what is wrong, here are the errors I am getting which show something about a driver connection error. What I am trying to connect to is the JDBC-ODBC Bridge driver using the Class.forName() method.

Exception in thread "main" java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
    at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6956)
    at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7113)
    at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3072)
    at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
    at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
    at java.sql.DriverManager.getConnection(DriverManager.java:579)
    at java.sql.DriverManager.getConnection(DriverManager.java:243)
    at databasequery.DataBaseQuery.<init>(DataBaseQuery.java:32)
    at databasequery.DataBaseQuery.main(DataBaseQuery.java:24)

//code here

package databasequery;

//imports
import java.sql.*;
import java.io.*;
import java.util.*;

public class DataBaseQuery{

    //variables
    static String FirstName;
    static String LastName;
    static String ID;
    static String Symbol;


    public static void main(String[] args)throws Exception{
        DataBaseQuery q = new DataBaseQuery();
    }

    public DataBaseQuery()throws Exception{
       //driver manager
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       //stockTracker URL
       //connection
       Connection Connection = DriverManager.getConnection("jdbc:odbc:StockTracker");

       //Connection Conn = DriverManager.getConnection(
       Statement Statement = Connection.createStatement();

       //Query
       ResultSet Result = Statement.executeQuery("SELECT * FROM Users");

       System.out.println("Stock by username");

       //loop through the results
       while(Result.next()){
           ID = Result.getString("userID");
           FirstName = Result.getString("firstName");
           LastName = Result.getString("lastName");
           System.out.println("ID: " + ID);
           System.out.println("First Name: " + FirstName);
           System.out.println("Last Name: " + LastName);
        }
    }
}
3
  • Are you using Java 8? Commented Jun 8, 2014 at 23:09
  • I remember that there were some incompatibilities for the JdbcOdbc drivers, you should try to look for them in Google Commented Jun 8, 2014 at 23:12
  • Is your ODBC connection defined? Commented Jun 8, 2014 at 23:13

1 Answer 1

1

From the docs:

... JDBC-ODBC Bridge ... will be removed in JDK 8. In addition, Oracle does not support the JDBC-ODBC Bridge. Oracle recommends that you use JDBC drivers provided by the vendor of your database instead of the JDBC-ODBC Bridge.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.