Go Back   nV News Forums > Software Forums > Software Development

Newegg Daily Deals

Reply
 
Thread Tools
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
Old 04-01-08, 07:10 PM   #2
rhink
Registered User
 
Join Date: Jul 2005
Posts: 434
Default Re: JDBC Help!!!!

Windows doesn't know where the database is. To set up MS Access for use with ODBC/JDBC, you need to configure ODBC sources. Assuming Win2k/XP, Control Panel->Administrative Tools->ODBC Sources. Add->Microsoft Access Driver, and configure it to point to your mdb file.
rhink is offline   Reply With Quote
Old 04-01-08, 09:45 PM   #3
jcrox
Mahna Mahna
 
jcrox's Avatar
 
Join Date: Jul 2006
Location: Madison, Wi
Posts: 6,134
Default Re: JDBC Help!!!!

I figured it was something like that. Thanks!

Edit: That was so easy. It really pisses me off how much time I wasted on this when all my instructor had to do was tell me that little bit... makes wonder WTF I'm paying all this money for.
__________________

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
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 06:13 AM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.