SQLException: No data found

Posted on 1998-11-28
Last Modified: 2009-12-16
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 {
        } catch(java.lang.ClassNotFoundException e) {
            System.err.print("ClassNotFoundException: ");

        try {
            con = DriverManager.getConnection(url,"test","test");
            stmt = con.createStatement();

        } 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?
Question by:conick
  • 4
  • 2
LVL 16

Expert Comment

ID: 1228363
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 ?

>>   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.)
LVL 27

Expert Comment

ID: 1228364
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?

LVL 16

Expert Comment

ID: 1228365
>> 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 :)

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.


Author Comment

ID: 1228366
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>

LVL 16

Expert Comment

ID: 1228367
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());
  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

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 ...

Author Comment

ID: 1228368

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"
LVL 16

Accepted Solution

heyhey_ earned 100 total points
ID: 1228369
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

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question