Also; can I add a negative INT inside a PRIMARY KEY column inside a table via JDBC?
views:
63answers:
2There should be no reason why you can't have a negative number in a primary key field, unless you are using an unsigned integer as its data type.
When you don't have a primary key defined (or a unique index for that matter), the database server has no way of knowing that the rows are unique. Being able to tell one row from another is pretty fundamental when it comes to databases, and I think maybe the designers of MySQL probably are forcing this on you -- I don't know, since I don't use MySQL all that much... It's a problem that I've never ran into, to be honest, because pretty much every table that I ever create has a PK!
Why is it necessary to assign atleast one column in a table (in MySQL) as PRIMARY KEY for the table to accept UPDATE and INSERT statements via JDBC?
This is not a JDBC limitation. This is a database limitation. Consult DB-specific docs for answers.
Also; can I add a negative INT inside a PRIMARY KEY column inside a table via JDBC?
This is not a JDBC limitation. This is a database limitation. Consult DB-specific docs for answers.
To make things clear: JDBC is here just a simple tool to give you the ability to execute the SQL language using the Java language. If you get exceptions of java.sql
package, then the problem more lies in the faulty SQL syntax used, or a limitation in the database in question, or in rare cases a bug in the DB-supplied JDBC driver, but it certainly isn't caused by the JDBC API in general as you seem to think.