Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SQLException: [Microsoft][ODBC Driver Manager]

 
Glenn Castro
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It's my first time to use JDBC and I got the following message on running a simple JDBC code.
SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
How can I resolve this problem. Can anyone teach me how to setup the database and what should i put on the following code:
import java.sql.Connection;
import java.sql.*;
public class CreateCoffees {
public static void main(String args[]) {
String url = "jdbc dbc:COFFEEBREAK"; //COFFEEBREAK is the name of the DB
Connection con;
String createString;
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
Statement stmt;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
try {
con = DriverManager.getConnection(url, "sa", "");
stmt = con.createStatement();
stmt.executeUpdate(createString);
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
}
}
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like your computer can't find the datasource named COFFEEBREAK. Make sure this ODBC datasource is set up on your computer and that it is spelled the same as in your java app.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What OS are you using? I will assume win2K. It has to be windows.
"COFFEEBREAK" is the name of the datasource not the database file name.
to set up a datasource go to control panel. Open administrative tools. Double click "Data Sources(ODBC)" go to system DSN tab. choose add. Pick the microsoft access driver. give it the datasource name COFFEEBREAK. choose create, and give it whatever filename you wish and put it where you like.
You are all set.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic