problem occuring when i am inserting date - mysql

while inserting date mysql server takes the year and day correctly but the month is defaultly taking januavary into the database.
i am using mysql server version 5.0.22
i am inserting the date though application.
the application was developed by using Springs web mvc frame-work and Hibernate.

Can you display the mysql INSERT statement which is being used to insert the data into the database? This would indicate whether it is a malformed INSERT statement or whether it is a valid statement using incorrect data.
Once you know what is happening, you can track down where the problem really is. I would guess it is a faulty date-parsing function.
Another possibility is that the software is expecting the date in European format (dd-mm-yyyy) and getting the entry in US format (mm-dd-yyyy) or vice-versa. And this is causing parsing errors.

Related

Coldfusion and mySQL 5.6.41 returning datetime errors due to extracted format 2021-02-07T15:32:54

I am getting errors in Mac OS Coldfusion 2016 reading a mySQL 5.6.41 database with field type of datetime. A simple cfquery select * with cfdump produces java class error "java.time.LocalDateTime" on the datetime fields while producing expected data output in all other fields.
Attempting to output the field value as text, it returns the date/time with a T separator '2021-02-07T15:32:54' (which could be parsed).
But no ColdFusion date/time functions work due to this format.
The data was exported from mySQL 5.6.19 via SQL export using Sequel Pro and imported into the new 5.6.41 instance. All code runs fine on the previous server. I have attempted using the installed mySQL 5 datasource in ColdFusion and a JDBC driver. Both connect fine, but produce same DATETIME format.
Changing the field type to DATE or TIMESTAMP allows the CFDUMP to display without error in the DATETIME fields (obviously minus TIME if DATE).
There is a large amount of labor/overhead involved to not be able to keep DATETIME working as built (plus I believe its the correct field type). I have run out of google options and hoping someone can explain the difference and reason and solution the Coldfusion 2016 will not query data in the same manner as similar code/server.
The only way I solved this was to remove mysql-connector-java-8.0.28.jar and replace it with an older version - mysql-connector-java-5.1.38-bin.jar in my case. So, the problem comes from the mySQL connector.

Spark jdbc write (to MySQL) missing milliseconds in DATETIME and TIMESTAMP columns

There are similar questions, but I am beginning to think mine is related to Spark jdbc APIs since both components seem to be working correctly on their own. I am using Spark 2.4 (which has ms support for timestamps) and have a MySQL 5.7.x version that supports fractional seconds.
I created a simple Dataset, with a TimestampType column, and when I show() it, here is what I get:
+-----------------------+
|my_timestamp |
+-----------------------+
|2021-02-06 12:11:45.335|
+-----------------------+
When I write this to MySQL (using dataset.write()), it creates the table automatically, with SQL TIMESTAMP type for the column, and the milliseconds part is lost upon insert.
For a second test, I created the table manually and defined the colon as TIMESTAMP(3). When I manually insert timestamps with ms part to it, everything works correctly. But when I write using Spark jdbc APIs, once again the ms part is truncated and it becomes 2021-02-06 12:11:45.0.
The only workaround that comes to mind is to keep the column as a long/BIGINT and convert it to DATETIME/TIMESTAMP when querying.
Am I doing something wrong here?
Well, StringType to the rescue. Apparently if I keep the Spark column as String with a value formatted the way MySQL expects, e.g. "2020-11-20 23:06:41.745", I can insert to a MySQL TIMESTAMP(3) column without any truncation or other problems.
This feels more like a workaround, so I still want to learn if there is a way to do this correctly.

SQL 2008 remove smart quotes before data insert

I have a VB.net web service that inserts data into a SQL 2008 DB. A lot of the data is being pulled from a word document. So we recently ran into an issue where smart quotes and a funky looking apostrophe was inserted into the data column. It inserted fine. My issue is that we are pulling the data from the DB and sending it back to the user as JSON. So when the user tries to look at the data they get an unexpected end of JSON when it tries to read the funky characters.
Can I do something in my VB code before I insert it or is it easier to do in the SQL insert stored procedure? Any suggestions would be greatly appreciated.

How to get last access date for a SQL Server database?

I have a development server that is getting crowded.
I would like to see what date the databases have been accessed to determine what ones can be deleted. Is there a way to do this?
The only thing I found when searching was for postgredb:
How to get last access/modification date of a PostgreSQL database?
If you have a table that always gets values inserted you can add a trigger to the update/insert. Inside this trigger you can set the current timestamp in a dedicated database, including the name of the database from which the insert took place.
This way the only requirement of your database is that it supports triggers.

Active Record and migrating malformed dates

I've got a legacy database that was running on CakePHP and MySQL that's being migrated to a new Rails App on a Postgres database with a wildly different structure. I have one small piece of migration that's giving me fits, and I'm hoping someone here can point me in the right direction.
Essentially, there are date columns (of MySQL type Date) that contain malformed dates. Most of the malformed dates are of the form '2012-08-00', and the MySQL2 adapter chokes on these (as obviously 00 is not a valid day of the month). If I could just get them into the model I could do the necessary conversions to turn them into the much more complete new format. Even getting them out of the Database as a string would be sufficient, I could do the necessary manipulation that way.
I get the following error:
Mysql2::Error: Invalid date: 2011-12-00
whenever I try to select one of the invalid dates from the system. There are 3800 rows in the table, I would estimate that about half are so attempting to go through and modify them all by hand would take a great deal (but not inordinate, if that's the way it needs to be done) amount of time.
Any suggestions would be highly appreciated!
Something like this should work (not tested):
update [table] set [field] = DATE_ADD([field],INTERVAL 1 day) where day([field]) = '0'