I have done a lot of internet searches, and can't find a report of a problem quite like this one, so I'm hoping someone here might have an idea of what is going wrong. In my java code I have a query that is pulling data from the database. I have confirmed that the SQL is well-formed, and all of my other queries in this java file run fine. In fact, even this query runs as it should when I am using the dev test Tomcat server. However, when I try to run this particular query using the dev test Resin server (where it was working perfectly fine up until just recently), or the QA test server, which also uses Tomcat, I get this error:
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '131500'
The '131500' I'm assuming is coming from the time portion of the first datetime value that is returned, which is '13:15:00'.
The particular part of this query that is causing the problem is this line:
CONCAT(DATE_FORMAT((SELECT datenotime), '%Y-%m-%d'),' ',DATE_FORMAT((SELECT appointmenttime FROM appointments WHERE appointmentdate = datenotime AND appointments.service_id = service.id), '%T'))
If I remove this then I experience no problems on any server, so it only occurs when the time is formatted and concatenated. I would think that the issue here must be some server setting? Although there were no recent changes made to the Resin server that I know of. I tried updating Resin's msyql connector jar, but that didn't help. Does anyone know what is going wrong?
Thanks!
My guess is that you are getting this error when datenotime is null.
That would make sense, since you are concatenating datenotime and then appointmenttime. If datenotime is null, then all you have left is time, which simply can't be converted to any known datetime value.
Related
I made a Java Web Application hosted by Tomcat. It can be found on this URL.
The problem that I am experiencing is that whenever I visit the page the first time it takes about 10s while every time after it it takes only 100-500ms. I would say the speed improvement is due to browser caching, but not really, when I refresh cache too (ctrl+shift+r) I get the same quick response.
Then after some time, about 5 minutes I visit the page again and it's slow again.
You may try some tests yourself on the URL provided by changing the search parameter value to e.g.: 1050,1051,1052,2670,4000,2300,2200.
Also the interesting fact I have spotted is that no matter how big payload (compare 1050 with 2300) the time is almost always the same approx. 9-10s. So what I assume is that something like Java Server has got to get ready and that is what is taking time.
EDIT:
I was first thinking it could be related to Java/Tomcat having to load some resources and then after some time +-3-5mins again because for some reason it unloaded it. But as I wrote above, even if I change the URL query string (that causes a different SQL query during execution), it again loads long. Can the issue be related to the DB? I am using MySQL.
EDIT2:
The reason why it's faster is most likely the server caching. I am 95% sure and that is because I made couple of experiments such as trying it on 2 computers etc. (no it's not browser caching). Then I realized that if it's fast only when it's cached, what takes so long is the actual .executeQuery line of code. It takes 10s even though the exact same request through a client such as WorkBench takes only 0.285s. Therefore I am going to try to use a PreparedStatement or experiment further.
The content is 200kB in size. You need to optimize it in the front and backend.
The main problem is in your backend. Check why it takes so long.
In the frontend you can enable gzip compression. Check the tomcat documentation on how to do it. This will reduce the size for the download.
The second time is probably faster for you due to browser caching.
Check the response code in Firebug, if the response is 304 it is cached. Response 200 means it has been loaded from the server.
ORM systems (like Hibernate) can cause significantly slow startup if you forget to turn off the initial modell-schema sync option in production environment, for example in Spring -> JPA -> Hibernate -> application-[server].yml->
spring:
jpa:
hibernate:
ddl-auto: update
update none
If your model didn't change, switch "update" to "none" in the production environment for faster startup.
I am building an app and I can't seem to handle the data that contain diacritics or other type of UTF-8 characters. In my case I'm in need of this chars: ă-Ă-â-Â-î-Î-ş-Ş-ţ-Ţ.
Now, first, there is a input on the front-end that gathers some info from the users, sends it via AngularJS http module to the API. The headers are all good, the data goes to the API all good. Then, on the server side, if I log the info, it outputs: ?-?-â-Â-î-Î-?-?-?-?, and of course, the same info is put in the db (checked with phpmyadmin).
The weird thing is, as my app pulls the data from the db to print it to my app, all goes well, it prints as it should be ă-Ă-â-Â-î-Î-ş-Ş-ţ-Ţ, until I restart the server, after which it prints as it is shown in the db.
I want to point out that it isn't the cache, I'm testing the app in cache-free environment. I even tried to access from different end-points just to be sure it is not from some local issue.
Anyone has any ideas ?
I solved it myself: the problem was from JPA persistence level from Java. It didn't interpret the UTF-8 right because I was giving it inside the url. Actually what I needed to do was to create a parameter in glassfish jdbc.
I'm building a system with a login. When I was just testing it on my own computer, it worked perfectly fine. Once I uploaded it to our server, we started running into the problem whereby ... it wouldn't log in in the morning, for a few seconds. Works fine the rest of the time.
I've only run into this yesterday and today, and I can only test it once each morning, so it's hard to give too many details yet. Here's the setup:
The front page is an html page using javascript and angular js. It brings up an empty frame, then makes an ajax request for the contents of the page. On any failed ajax request that has a return value of 'insufficient access priviliges' it will un-hide a div holding a login form. That login form blanks out the page and provides a submit button. Once the submit button is clicked on, it sends an ajax login request to the Java server. Once that request is returned, the page hides the login form again, and things move on as usual.
On the back end, we have a java server running something between 1.6 and 1.7 (yes, I know, I should know better - the server reports back that it's 1.7.001, but 1.7 functionality like string-based switch-case statements don't work, so we compile for 1.6 java when uploading. It's a known issue we're working on.) We're using Stripes to do the front-facing code. The database is a mysql database, located on the same server.
When this error occurs, it's always the first login in the morning. I load up the page, type in the user/pass, and click login. The page blinks and comes back to the login screen. I haven't cleared out the user/pass after a login yet, because we're still in a testing phase, so I can just click 'login' again, and again, a dozen times before it finally logs in. This problem has only happened twice: yesterday and today, the first login of the morning.
My co-worker had a similar issue with another similar setup on a previous project, same server. He said he believes the problem has to do with the sql server closing the connection without the java server realizing that the connection has been closed, but he's not sure, and doesn't know how to fix it.
I don't even know what other information to offer, what code to show, or anything like that. The best suggestion I can find anywhere is "Set up a scheduled event to make a sure-fire database request every couple of hours," but this seems so ... kludgy. I'd love to be able to test for a more definitive problem and solution, if anyone could help me out. If anyone can tell me what code they'd like to see to figure this out, I'll gladly paste it up. More information? Just ask. The scope seems so ... big ... that I don't know which pieces might be relevant.
Edit 1: Error code!
[ERROR] - Database Error 1 on verify
java.sql.SQLException: Already closed.
at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:114)
at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)
Edit 2: Connection Code
This is from an object we keep specifically for all mysql database connections.
private static ConnectionSource coreConnection = null;
private static DataSource coreDataSource = null;
public static ConnectionSource getCoreConnection() throws SQLException, NamingException {
if (coreConnection == null || !coreConnection.isOpen()) {
Context env = (Context)new InitialContext().lookup("java:comp/env");
coreDataSource = (DataSource)env.lookup("webapps/test");
coreConnection = new DataSourceConnectionSource(coreDataSource, new MysqlDatabaseType());
}
return coreConnection;
}
Configure your connection pool to validate connections. The connection pool will then send a simple query (which you specify during configuration) to the DB. If that query fails, it will close the connection and give you a new one, otherwise it will use it in place. That helps solve problems like these as well as problems where the database goes down behind the back of the server.
MySQL closes connections which have been open for a long time, but don't do anything. From what you've described it sounds like this is what you're running in to.
The first login fails because it finds that the used database connection is no longer working, and the driver notices this as well. The driver will then use a new connection for the next request.
The first way to handle this that comes to mind is detecting this SQLException, and handling it by opening a new connection with the same query. There may be other solutions available within the driver that you're using, but unfortunately I am not aware of any.
To aid with detecting this SQLException you can take a look at the docs, and evaluate if the methods listed there return anything unique to this error.
If you are using a connection pool, then this question may contain the answer to keeping the connections alive.
I'm building a website with play! framework, I've finished coding and testing with in memory database, and everything was fine, so I decided to push the code to my server. But I encountered with a strange error, it says, "A database error occured : Cannot connected to the database, Unknown database 'fpn_server'".
I did change the application.conf file in conf folder, I set the application.mode to prod(quite sure this has no connection with database), set the db property to "mysql:root:mypass#fpn_server", and jpa.ddl to "create" to make sure the database got created.
Well, to be honest, I developed a demo website with the same database name, and it was successfully deployed on my server. But this time, the schema changed, I did NOT use the evolution scripts as the documentation said, I simply dropped the database from mysql server. Not quite sure if this is the mistake.
I've been googling around for a while, an no good.
BTW, I'm usin play 1.2.4 not play 2.
Can anyone help me? Any suggestion is welcome!
Thanks in advance.
You are using the shortcut MYSQL5 configuration, which appears fine. However, maybe you should try using the verbose settings.
%production.db.url=jdbc:mysql://localhost/fpn_server
%production.db.driver=com.mysql.jdbc.Driver
%production.db.user=root
%production.db.pass=mypass
If there is anything that looks wrong in the verbose settings, this could be responsible for why your shortcut settings are not making sense.
If the configuration looks fine, I would check that your database is accessible.
For reference, here is the application.conf database options - http://www.playframework.org/documentation/1.2.4/configuration#dbconf
Did someone face such an error happening in case of some queries execution? (jdbc4.CommunicationsException: Communications link failure)
Generally, this exception means some problem of communication between application and mysql. And you can find a lot of suggestions posted regarding possible reason.
Nothing helped in our case, and after several hours of investigation it turned out that the reason can be completely other.
Maybe the answer below will save someones time :)
So, it turned out that the reason can be a corruption of mysql data file!! Actually, it can be corrupted the way that mysql is normally functioning for the most of queries.
If you find the query which executes application (when CommunicationsException is thrown) and execute it directly, e.g. in SQLyog, you will see:
Error Code : 2013
Lost connection to MySQL server during query
First of all, have a look on domain.err log file of mysql. If you have similar case, there should be lots of errors reported, including message like:
InnoDB: Database page corruption on disk or a failed
What we have done to solve the situation quickly - we set "innodb_force_recovery" to 1. This means directive to MySQL: Let the server run even if it detects a corrupt page.
CommunicationsException disappears after setting this, and what remains - "simply" DB data recovery ;-)
All the best,
Edgar