I have with me a java app that uses mysql-- now I have converted the database to SQL Server- but I need to convert the code of the java app so that it now uses SQL Server.
This java app uses Struts and Hibernate
What all things do I have to keep in mind to make this conversion?
hibernate should make the transition seamless for you.
Make sure to choose the correct driver as some drivers might act differently.
I personally like jtds. It has vast documentation.
Look for native queries in your code because they might need some modifications.
Other than that, I don't think you should experience any problem.
I had an application that supported oracle, SQL-Server and mysql and we didn't have specific code for each one.
EDIT : as maba suggests in the comments, you will need to modify the hibernate configuration a bit (driver, dialect, url ).
For more hibernate specific configuration, I found a great stackoverflow answer
Related
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.
I would like to know which alternatives exist to replace DDL utils from Apache.
I ask this because ddlutils project seams to be Dead, and also it does not support H2 Databases. I've searched for it, and I found suggestions like liquidbase or flyway.
My problem is: These frameworks run when project starts and change DB structure based on some XML files. They are really designed for Database Migration.
What I want is a framework to CREATE/ALTER Tables in Runtime, in a high abstraction level., i.e. supportting at least Mysql, Sqlserver, oracle, and H2.
For example I could tell to the engine that I want to create a table with a Field AGE with Type Number, and the framework would rephrase to:
create table MY( id bigint(20))
create table MY(id bigint)
create table MY (id, number)
depending on the underlying db engine.
Any suggestions?
I could see there is a patch for ddlutils, for it to support H2. However I wasn't able to patch my svn checkout...
Any help will be appreciated.
thanks in advance
rui
I know this is an old thread, but wanted to give a definitive answer.
Yes, DdlUtils is dead, hasn't seen an update in 2 years now.
However, it looks like the guys might have switched over to https://www.symmetricds.org. Their repo is https://github.com/JumpMind/symmetric-ds.
As soon as you scratch away at the surface, you'll find that the core of DdlUtils is still in there (even has some of the old Apache copyright notices).
Class names have changed, APIs have changed so there is not a 1-to-1 mapping, but it is getting regular updates and includes H2 and other database support. Honestly I'd rather be getting those things instead of keeping the old APIs.
You're not going to find a guide on using Symmetric DS in the same way as the old DdlUtils doco, but there is enough in the code that you should be able to piece it together.
Take a look on jOOQ it is very useful in generating DDL (and DML too)
create.createTable("table")
.column("column1", INTEGER)
.column("column2", VARCHAR(10).nullable(false))
.constraints(
constraint("pk").primaryKey("column1"),
constraint("uk").unique("column2"),
constraint("fk").foreignKey("column2").references("some_other_table"),
constraint("ck").check(field(name("column2")).like("A%"))
)
.execute();
This looks promising: https://bitbucket.org/aragot/play-sql-dialects/src
At least as a start.
Mogwai ERD designer might help though they do not formally support H2 but you could put H2 into compatibility mode with one of the supported DB systems: https://sourceforge.net/p/mogwai
i am new in playframework i know how to install playframework and connect it to the database . Is there is any tutorial for that like how to perform sql operation using java in playframework.
SQL is not dependent on the Play Framework; it's dependent on the database you choose to use as a store for your Play Framework application.
W3 Schools has a pretty good tutorial for basic SQL operations. You can also look up additional commands and functionality provided by your specific database provider in the docs for that database. e.g. look here if you've chosen to use a version of PostgreSQL
The problem is confused slightly in that what I think you need is a method for your application to map rich application objects to flat database tables. This task can be done using an Object-Relationship-Mapping or functional-mapping tool. Ebean is an example of an ORM and Slick is an example of a functional mapping tool, both of which can be used in Play applications by adding their drivers to your /project/build.scala file in the list of your project dependencies.
Setting up Ebean for your Java-based Play project is covered on the page of the Play 2.1 Java tutorial after the one linked to by bistros - Using the Ebean ORM
see playframework.com tutorial page.
http://www.playframework.com/documentation/2.1.x/Installing
http://www.playframework.com/documentation/2.1.x/JavaDatabase
You can start direct with examples from the website. I think this one is very nice to understand how to work with database.
play-java-ebean-example
I am working with Jsbs and want to select a DBMS for my application that require a native XML database. Can you people guide me?
1) how many DBMS are supported by Java (is it true almost all DBMS are supported by java?)
2) Which one will be the best selection for XML storage and retrieval?
Thanks in advance.
Here is a list of JDBC Drivers and the DBs they work for. Probably every database out there has a JDBC driver.
As far as supporting XML it depends if you want to be able to do queries against the XML or not. Most modern DBMSs support XML to some degree. Do you have one you are already using, or that you are recommended to use ?
1) Yes, there are JDBC drivers for all the major DBMS (Oracle, MySQL, Postgres, DB2...) and also some interesting java DBMS like HSQL
2) As far as I know Oracle, DB2, PostgreSQL (and probably MySQL) all have XML column types
It is not obvious to me that you need anything more than support for Blobs or Clobs to implement simple XML storage and retrieval. You'd only need special XML support if you needed to perform queries against the data contained in the XML.
What you are talking about is an "XML enabled" RDBMS. Depending on your actual requirements, you may also want to look into native XML databases (NXDs). There is even a standard Java API (XQJ) for querying NXDs, though not all vendors support it.
Most modern databases have JDBC-drivers, which is what is needed for Java programs to connect to the database. You generally want type 4 drivers which do not depend on native code.
For starting I would recommend Apache Derby, which is written in Java and can be part of your program, which keeps it simple. http://db.apache.org/derby/. If you later find you need another database you replace the JDBC-driver, and double-check your SQL-statements.
I am making a desktop application in java and using MSAccess in data base.
I want that if i run the setup of the application the database should be created on client machine because there can be different client using the application and how can i create the setup?
is there any tools available for this free of cost?
please explain me in detail..
thanks
Java 6 (enhanced for desktop application work) comes with a built-in database called JavaDb (formerly IBM's Derby). That will do what you want.
Here's a set of guides and tutorials on how to use it.
I would suggest that when your application first starts, it checks for the presence of the created database, and if it doesn't exist, it builds the database (via the appropriate SQL). I've used this approach before and it works quite well.
I prefer nullsoft. Take a look at Open Source Installers Generators in Java
#pratap: database should be created on client machine..
Add an empty access database to your setup.
Have a look at SQLite, which is used by Mozilla (Firefox stores all bookmarks and history in a database) and several other major applications.
When you say
access in database
do you mean Microsoft Access or access the data in a database.
I would advise against MS Access if that is the case. If not, you could either use the JavaDB or HSQLDB and the use SQL scripts to create the database. As a summary
Package the application in one of the installers (InnoSetup or NSIS are good ones)
When installing, extract all the files in proper folders
Execute the SQL scripts before first running the application to ensure the database is setup, you can do other housekeeping tasks along with this step (refer to installer documentation for after-install steps)
Your application is good to go
In the last distribution of NetBeans I used, there was a wizard to create such application. The application used the Java Persistence API to store the Data.
My option is HSQLDB since it's fast, reliable and easy to use.
In the documentation it's explained how to use the standalone database mode, this is primarily used for unit testing but it fits your case too. The good thing with this is that you just connect to the file based database without any special set up and if the files doesn't exist, they're created.
I would second the posters who recommend JavaDB.
It is absurdly easy to adminster from inside your application. Whats more because everything is native Java you dont get the char->unicode little-endian->big-endien and all the other conversion malarky you normally get when reading SQL into java.
The one tip is that with JavaDB is prepare your SQL statements. Prepared statements get cached and the resulting access program (similar to an access plan but actually a jvm program) is reused, the programs for "executed' statements are not cached.
If you are really set on MSAccess then I would suggest you package an "default.mdb" file with all your required tables defined and your classifcation tables populated. If the user's table does not exist then simply copy over the default .mdb file and open that.
I recommend the H2 database because it is simple, fast, pure Java, and small. See this page for how H2 compares to other Java databases, including those mentioned here in other answers. It has many features Derby/JavaDB and HSQLDB do not.