Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Data source name not found and no default driver specified Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

Data source name not found and no default driver specified

Shyam Hai
Ranch Hand

Joined: Feb 04, 2009
Posts: 68



I create very simple program with JDBC.


package code.sample;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

public class DemoJDBC {
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbcdbc:local","smsiss","smsiss");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT country_cd FROM country_code");

while(rs.next())
{
String one = rs.getString("country_cd");
System.out.println(one);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

When i run this program that time i get this exception.

Exception-
---------------------------

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:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3074)
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:525)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at code.sample.DemoJDBC.main(DemoJDBC.java:15)
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Did you create an ODBC datasource named local in windows?


OCUP UML fundamental and ITIL foundation
youtube channel
Shyam Hai
Ranch Hand

Joined: Feb 04, 2009
Posts: 68
hai
No i am not create local.
now changed the Data Source name: dBASE Files.

Now i got Exception:
java.sql.SQLException: [Microsoft][ODBC dBase Driver] The Microsoft Jet database engine could not find the object 'data_provider'. Make sure the object exists and that you spell its name and the path name correctly.
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
at sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:253)
at code.sample.DemoJDBC.main(DemoJDBC.java:15)
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

You need to configure the data source in ODBC before you can access the database. Failing which you are going to see those exceptions


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Amulya Gupta
Greenhorn

Joined: Jul 12, 2009
Posts: 1
hello...
help needed!!
i want to use SQL10g as my backend and want to have jdbc connection...
code is:

import java.sql.*; // imports the JDBC core package
public class jdbc{
public static void main(String args[]){
String Dname;
String Location;
// SQL Query string
String query = "SELECT dname,loc FROM dept;";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); // load the JDBC driver
Connection con = DriverManager.getConnection ("jdbcdbc:Inventory");
// get a connection
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query); // execute query
while (rs.next()) { // parse the results
Dname = rs.getString("dname");
Location = rs.getString("loc");
System.out.println(Dname+", "+Location);
}
con.close();
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
}
}
}

but when i run the error is

java.SQLException: [Microsoft] [ODBC Driver Manager] Data Source name not found and no default driver specified


please help me...if you could tell me how to configure ODBC data source it will be really nice of you!!!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

if you could tell me how to configure ODBC data source it will be really nice of you!!!
http://tinyurl.com/mtwtdk
Mark Darwin Nacionales
Greenhorn

Joined: Feb 19, 2012
Posts: 2
I know the post was years ago but I felt like answering the question for those who are just experiencing this right now. It took me a while to know the answer to the question so here's the solution:

http://wiki.netbeans.org/FaqSettingHeapSize

Follow the "Running the 32-bit JVM".

All you have to do is find the netbeans.conf in the installation folder of your netbeans and change the directory from something like this:

netbeans_jdkhome="C:\Program Files\Java\jdk1.6.0_24"

to this:

netbeans_jdkhome="C:\Program Files (x86)\Java\jdk1.6.0_21"

The problem is netbeans might be running in 64 bit but MS Access only support 32-bit. So doing this would hopefully solve the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Data source name not found and no default driver specified
 
Similar Threads
Connecting to DB Error
Connectting to MS Access in Remote machine without DSN
Need help
Connecting To Database
how to connect ms acess in java