Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

SQLException: No data found

Im trying to create the following table (taken from Sun's tutorial on JDBC)
Im trying to use MS Access on a Windows 95 machine and have JDK1.2rc2
Heres what Ive done so far:
--Went to Control Panel (Windows95)
--clicked on 32bit-ODBC
--added a data source on MSAccess Driver
--set up the data source name -- "test" and gave it a description
--clicked advanced and gave it a login name and password ("test" -- "test")
I then compiled the source below and tried to run it
The error message was:
SQLException: No data found

I also tried to set the the driver for the data source to be SQL Server and got SQLException: SQL server not found

import java.sql.*;

public class CreateCoffees {
    public static void main(String args[]) {
        String url = "jdbc:odbc:test";
        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,"test","test");
            stmt = con.createStatement();
            stmt.executeUpdate(createString);
            stmt.close();
            con.close();

        } catch(SQLException ex) {
            System.err.println("SQLException: " + ex.getMessage());
            System.err.println("SQLState: " + ex.getSQLState());
        }
    }
}

I read in the locked questions the following:
"In case of sun jdbc-odbc bridge for java applications you don't have to install anything on webserver
but the problem is thats not available for MS Access."  -- Arooj
Is this the reason for my problem or am I taking this out of context?
0
conick
Asked:
conick
  • 4
  • 2
1 Solution
 
heyhey_Commented:
i tried your example
- created Datasource "test", user "test", password "test"
(chosing new Database - so creating new .mdb file)
- copy & paste your java code
- compile it and run it

and everything worked OK
i have new table COFFIES with 5 columns in my .mdb file

tested on WinNT, jdk1.1.7A, MS Access 97, Access ODBC driver version 3.50.360200,

and i've never experienced such problems ... maybe you haven't configured the ODBC datasource or you have older ODBC driver ???

more help needed ?
  heyhey

P.S.
>>   I also tried to set the the driver for the data source to be
>>  SQL Server and got SQLException: SQL server not found
it seems that ODBC driver works, but it can't find thge SQL server, if you can see this DataSource from Access, it should be possible to see it from Java
(Access / Create new Database / Get External Data / Link Tables then chose "file of types" ODBC Databases.)
0
 
BigRatCommented:
Just a small thing from a silly mouse like me. I don't have my JDBC manualy with me, but is "stmt.executeUpdate(createString);" the correct call for creating a database table?

0
 
heyhey_Commented:
BigRat:
>> Just a small thing from a silly mouse like me.
maybe you are Big, but you are not silly :))

yes "stmt.executeUpdate(createString);" is the correct statement
>> public abstract int executeUpdate(String sql) throws SQLException
>> Execute a SQL INSERT, UPDATE or DELETE statement.

and it even works :) (on my system :)

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
conickAuthor Commented:
Im running the following:
MSAccess for Windows 95 version 7.00
ODBC Driver:       3.50.342800    odbcjt32.dll   12/4/96
So it is an older ODBC driver.. but the Access version is also older
Maybe this is the problem??

I tried to see the data source from Access and I could (under Machine Data Sources not File Data Sources)

I never set up an initial database before I ran the java code... Do I need to do something in Access before I run it?
I have since set up "test.mdb" and tried to run it.  No dice.

This is incredibly frustrating...
Raising points to 100

<Warning: here comes a vent>
Does anyone else get upset when you read help files and it uses tons of acronyms that you dont know what they stand for?
<end vent>

0
 
heyhey_Commented:
hmmm ...
and i'm using 'only' jdk1.1.7  - maybe this is the problem :-)

add 'pint stack trace' line in the exception handler
  System.err.println("SQLException: " + ex.getMessage());
  ex.printStackTrace();
  System.err.println("SQLState: " + ex.getSQLState());

you'll see the file and line number where exception occures ... (post this information here). probably you can decomile these classes (if they don't come with sources) and see what is the exact problem (of course if the problem is in the bridge, not in the ODBC driver itself)

hope this helps
  heyhey

P.S. i just saw this line
>>  never set up an initial database before I ran the java code...
i think that you NEED to set .mdb database when you create the datasourse, so that the ODBC driver has some physical object to act over ...
0
 
conickAuthor Commented:
AHHHH  HAA!
eurika!

As you said you need to have a physical object for the driver to act on...
I created the *.mdb in Access and did not assign it to the datasource

In other words: I created the data source but didnt give it a file to act on
(in the control panel)
I needed to click on either <Create> or <Select> to configure the database for the data source
which I didnt do
post an answer and ill give ya an "A"
Thanks!
0
 
heyhey_Commented:
:)
it was on the third line

>> tried your example
>> - created Datasource "test", user "test", password "test"
>>> (chosing new Database - so creating new .mdb file)

best regards
  heyhey
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now