| Author |
Java&sql mystical problem with Switch
|
torsti koistinen
Greenhorn
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
|
|
Torsti, 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. Firstly, 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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26193
|
|
Torsti, 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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: Java&sql mystical problem with Switch
|
|
|