Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes JDBC and Relational Databases and the fly likes Java&sql mystical problem with Switch Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Java&sql mystical problem with Switch" Watch "Java&sql mystical problem with Switch" New topic

Java&sql mystical problem with Switch

torsti koistinen

Joined: Jul 29, 2004
Posts: 4
First, I am sorry about my broken English.
I have created simple project manager software with MySql and Java and I got this little problem.

my problem: : java.sql.SQLException: No row count was produced
-so there is something wrong in my code, but I can�t find out what is wrong
If I do those sql-clauses without switch they work.

This is what i am trying to do: Sql-clause should check is there this days(2004-07-29) field in database if there is sql-clause should only update hours(user given) of the day, but if there is not this days field sql-clause should create it. That�s why I need switch.

I have tried to resolve this problem days.
If someone could please help me
Jeff Walker
Ranch Hand

Joined: Apr 25, 2004
Posts: 116
well, this doesn''t look like standard JDBC to me at all! That would answer why no one has replied to your request for help. They can't help you.

Here's why I think your using non-standard JDBC.
in JDBC, you supposed to get an object that implements the Connection interface from a DriverManager, or from a DataSource. In your code, you just new a Connection() class, so I suspect somebody where you work wrote a very special Connection class to allow other developers to retrieve a connection easily (they probably did this to do connection pooling, but of course, that is a guess).

Second thing,
we don't know what your special Connection class does, but you are calling updatdeQuery() on it. In standard JDBC, you would get a PreparedStatement from the connection, or at least a Statement, and then call executeUpdate() or executeQuery() on that. So now, we can see your using a non-standard way of executing SQL statements.
Having said that, I suspect your call to conn.updateQuery(sqlClause) is not returning 0 or 1 at all, which is what you are assuming in your 'switch'. You need to put in a "default:" section into the 'switch' statement. Inside the "default:" section, write something like:
System.out.println("default: called, updateQuery() not returning 0 or 1");

-Jeff Walker
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33119

Watch the scope of your variables. The strings declared inside the switch statement are only valid in the switch statement.

I would go with an if statement rather than the switch. That way you can do an if/else to account for the two conditions without having to use a default case.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Java&sql mystical problem with Switch
It's not a secret anymore!