简体   繁体   中英

How can I change the currently used Database just by changing the configurations in Struts2

I have developed an application in Struts2 using MySQL at backend. But now as per interest I want to use Oracle at the back end.

For that I changed the db configurations to Oracle but I found that some of the MySQL queries are unable to run on Oracle directly.

I have searched too much and tried a few thing but still have no solution. Can anyone help here?

You can use Hibernate, it has dialects for both MySQL and Oracle. But if you use native queries then you should use separate code for each dialect.

In the BaseHibernateDAO you can create a method

protected Dialect getDialect(){
  return ((SessionFactoryImplementor) sessionFactory).getDialect();
}

Then you can use this dialect for any query you create.

In my opinion you've answered your own question. MySQL queries are not ALL compatible with ORACLE (example : LIMIT in MySQL would be ROWNUM in ORACLE). So if you have 'raw SQL' statements that involve specific terms for MYSQL you should change these to ORACLE.

However, if you are using Objects to generate the queries, this would/should be handled 'automagically' by the (for example) persistence solution you are using; just by changing the database driver in the settings.

For more details, we/I would need some examples of code that works on MYSQL and doesn't on ORACLE.

Let me know if that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM