Thread: JDBC Help!!!!
View Single Post
Old 04-01-08, 10:42 AM   #1
jcrox
Mahna Mahna
 
jcrox's Avatar
 
Join Date: Jul 2006
Location: Madison, Wi
Posts: 6,134
Default JDBC Help!!!!

I'm not getting this at all... I think my problem is that I'm doing the same exact thing in ASP.NET and it apparently is totally different in JAVA??

What I need to do:

I've downloaded a file: Employee.mdb, I need to access the file and print out the information. In ASP its really easy, put the file in my App_Data folder, connect to it, execute an SQL command and print it out.... for the life of me I can't figure out wtf to do in Java. The instructor gave us an example... I run it and I get an error stating there is no connection. Being the superb teacher that he is his only response to my questions is "we covered this in class" can someone help?? Here's what I have to make work:

Code:
import java.util.*;
import java.sql.*;

class DbTest {

public DbTest(){
}

public static void main(String[] args) {

DbTest dbtest = new DbTest();
Connection oConn;
Statement oStmt;
ResultSet oRS;

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
oConn = DriverManager.getConnection("jdbc:odbc:employee");
oStmt = oConn.createStatement();
String sql = "SELECT first_name, last_name FROM employee";
oRS = oStmt.executeQuery(sql);

while (oRS.next())
{
System.out.println(oRS.getString("first_name"));
System.out.println(oRS.getString("last_name"));
}

oRS.close();
oStmt.close();
oConn.close();
}

catch(ClassNotFoundException cnfe)
{
System.err.println("Error loading driver: " + cnfe);
cnfe.printStackTrace();
}
catch (SQLException se)
{
System.err.println("Error making connection: ");
se.printStackTrace();
}
}
}
I run it and I get:

Error making connection:
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:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java :7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.j ava:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOd bcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDrive r.java:174)

I have no idea where the employee.mdb file should be put nor how to connect to it. Help please!!! before I end up in jail for severely injuring my instructor

EDIT: I'm using netbeans 6.0 IDE
__________________

Gaming

MSI MPower Z87 | 4770k | CNPS9900MAX-B | 8GB G.Skill 1866 | EVGA GTX760 |ThermalTake 850w | X-Fi Titanium | HAF | Asus PA248Q | Lycosa | Death Adder | Win8 Pro 64

Dev/Backup

MSI GD65 | 2500k | H50 | 8GB G.skill | GTX570 | Ubuntu 13.10

Laptop

17" Inspiron | i5 | 4GB DDR3 | 500GB HDD | Win7 Pro 64

jcrox is offline   Reply With Quote