conversion of a varchar data type to a datetime data type resulted in an out-of-range value

Ambiguous date formats are interpreted according to the language of the login. This works set dateformat mdy select CAST(’03/28/2011 18:03:40′ AS DATETIME) This doesn’t set dateformat dmy select CAST(’03/28/2011 18:03:40′ AS DATETIME) If you use parameterised queries with the correct datatype you avoid these issues. You can also use the unambiguous “unseparated” format yyyyMMdd hh:mm:ss

Catch duplicate entry Exception

I use spring so we resolve it by org.springframework.dao.DataIntegrityViolationException try { ao_history_repository.save(new AoHistory(..)); } catch (DataIntegrityViolationException e) { System.out.println(“history already exist”); } But as @KevinGuancheDarias mention it: Please note that while this works. I suggest to solve the problem by issuing a findBy before the save, as this is messy, and I think it’s not … Read more

How to throw a SqlException when needed for mocking and unit testing?

I have a solution to this. I’m not sure whether it’s genius or madness. The following code will create a new SqlException: public SqlException MakeSqlException() { SqlException exception = null; try { SqlConnection conn = new SqlConnection(@”Data Source=.;Database=GUARANTEED_TO_FAIL;Connection Timeout=1″); conn.Open(); } catch(SqlException ex) { exception = ex; } return(exception); } which you can then use … Read more

Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 1, current count = 0

If you have a TRY/CATCH block then the likely cause is that you are catching a transaction abort exception and continue. In the CATCH block you must always check the XACT_STATE() and handle appropriate aborted and uncommitable (doomed) transactions. If your caller starts a transaction and the calee hits, say, a deadlock (which aborted the … Read more

java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x91\xBD\xF0\x9F…’

What you have is EXTRATERRESTRIAL ALIEN (U+1F47D) and BROKEN HEART (U+1F494) which are not in the basic multilingual plane. They cannot be even represented in java as one char, “👽💔”.length() == 4. They are definitely not null characters and one will see squares if you are not using fonts that support them. MySQL’s utf8 only … Read more

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

SQLiteOpenHelper onCreate() and onUpgrade() callbacks are invoked when the database is actually opened, for example by a call to getWritableDatabase(). The database is not opened when the database helper object itself is created. SQLiteOpenHelper versions the database files. The version number is the int argument passed to the constructor. In the database file, the version … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)