nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   Software Development (http://www.nvnews.net/vbulletin/forumdisplay.php?f=53)
-   -   JDBC Help!!!! (http://www.nvnews.net/vbulletin/showthread.php?t=110928)

jcrox 04-01-08 10:42 AM

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

rhink 04-01-08 07:10 PM

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.

jcrox 04-01-08 09:45 PM

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.


All times are GMT -5. The time now is 12:08 AM.

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