Solved

SQLException: No data found

Posted on 1998-11-28
7
965 Views
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 {
            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
Comment
Question by:conick
  • 4
  • 2
7 Comments
 
LVL 16

Expert Comment

by:heyhey_
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 ?
  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
 
LVL 27

Expert Comment

by:BigRat
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?

0
 
LVL 16

Expert Comment

by:heyhey_
ID: 1228365
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Author Comment

by:conick
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>

0
 
LVL 16

Expert Comment

by:heyhey_
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());
  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
 
LVL 7

Author Comment

by:conick
ID: 1228368
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
 
LVL 16

Accepted Solution

by:
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
  heyhey
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 62
ejb wildfly example 2 29
Selenium docs api java index 3 48
wild fly 8 startup error 2 14
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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

821 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