sqlexception

How to catch a specific SqlException error?

纵饮孤独 提交于 2019-11-26 04:18:35
问题 Q: Is there a better way to handle SqlExceptions? The below examples rely on interpreting the text in the message. Eg1: I have an existing try catch to handle if a table does not exist. Ignore the fact that I could check if the table exists in the first place. try { //code } catch(SqlException sqlEx) { if (sqlEx.Message.StartsWith(\"Invalid object name\")) { //code } else throw; } Eg2: without the try catch showing duplicate key exception if (sqlEx.Message.StartsWith(\"Cannot insert duplicate

java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver

做~自己de王妃 提交于 2019-11-26 02:36:38
问题 I\'m getting this exception when I try to run this program. It\'s one of the Microsoft examples. I\'ve added the sqljdbc4.jar to the classpath in netbeans for both compile and Run, via the project properties. I also tested that the class could be found by using an import statement below - no error during compile, so it must be finding the jar. Could it be related to a dll or some sql dll that the sqldbc4.jar references? This is the exact exception, and below is the exact code, except for

When is SQLiteOpenHelper onCreate() / onUpgrade() run?

北慕城南 提交于 2019-11-25 21:30:22
问题 I have created my tables in my SQLiteOpenHelper onCreate() but receive SQLiteException: no such table or SQLiteException: no such column errors. Why? NOTE: (This is the amalgamated summary of tens of similar questions every week. Attempting to provide a \"canonical\" community wiki question/answer here so that all those questions can be directed to a good reference.) 回答1: SQLiteOpenHelper onCreate() and onUpgrade() callbacks are invoked when the database is actually opened, for example by a