Properties file for database connection GWT - java

Hi is it possible to use a properties file in GWT that contains database details and then just change it anytime if for example, your database details change? This file would be read by java.sql.Connection so that the system could connect to the database. Thanks

It is possible to use files to configure GWT. Every GWT "module" has a definition xml file, and you can always define constants in your Java code too.
On the server side, you can use all of the Java tools you're used to, as long as your server supports them! GWT does not place any additional constraints on your server code.

I suggest you to try with an ORM (object-relational mapping) in order to handle your database communication. In this case you will naturally use a configuration-property file.
There is a good article that provides some info about using GWT with Hibernate.

Related

JSF, website first setup and external configuration files

I have a website written in JSF backed by MySQL database running on Tomcat 7. Now there is only one missing part - project first setup/installation. I want my war when deployed for the first time to offer you installation/first time setup with following steps:
Setup database - enter mysql parameters needed to successfully connect to mySQL server.
Write those parameters into some external file for further use (of course encrypted).
Install database - take a file with SQL inside that creates all the tables in database.
Create first user etc.
Delete installation files.
Similar steps are used in PHP Content Management systems like Drupal. I know perfectly how to work with files in Java. I also know, that I can't change content inside a jar once it's deployed and running, so I have to put my files with SQL and database parameters somewhere else.
My questions are
Where can I put these configuration files to make them readable ? And how ?
Is there another way to achieve this goal ? What is commonly used by Java developers ?
Thank you for your answers.
You can use JPA(Java persistent API) and put all this configuration on persistance.xml and set the schema generation to create Table also the things related to role and user is dependent to application server.
JPA use ORM(object relational mapping) to map between you objects (entity) and database tables

Access database(oracle) using XML in java

Is there any way to Access database from java using XML. I dont want to fire queries from my java code.I came to know about MLIP(Message Level Interface Port), but not much is available about it on internet.
Also got one link
http://docs.oracle.com/cd/B28359_01/appdev.111/b28369/xdb01int.htm#g1054540
But not getting clarity.My application is using jsp and servlets with MVC architecture and cant migrate it to framework like struts and hibernate.
I'm not sure, but I think MyBatis (formerly known as iBatis) is what is you looking for. It is a framework which eases accessing databases by extenalizing SQL queries in XML files and not Java code. So as far as your queries parameters and output are the same, you can manipulate manipulate them without need to change your Java code, or even recompiling it.
XML is a mechanism for formatting data so that is can be exchanged between systems. Although it is now used for other things it is not a database access protocol.
If you don't want to use JDBC then you must choose another protocol. Oracle XML DB supports FTP, WebDAV and direct access through HTTP(S). Find out more.
You might got the answer from below link.
http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/11g/r1/prod/datamgmt/xmldb/xmldb.htm

Switching between embedded Databases in Java with JPA

Im currently working my way towards JPA 2.0 and I start of liking how easy it is to maintain persistent data.
What I'm currently trying to accomplish is using JPA in a basic desktop application. The application should allow me to open embedded databases which are on my file system. I chose H2 databases for now, but I can really live switching to JavaDB or anything else.
What Im trying to accomplish is, that one can open the database file without previously define a persistence-unit in the persistence.xml file.
I can easily define a unit and persist objects, but it needs to be configured first.
I want to write some sort of database browser which allows opening without preconfiguration and recompiling.
http://www.objectdb.com/java/jpa/start/connection
I saw that ObjectDB allows access for this type of PersistenceFactory creation, but I was not able to transfer this example to other databases.
Am I totally wrong with the way I approach this probblem? Is JPA not designed with on-the-fly database access?
Thank you for your help,
Johannes
Not part of the JPA standard. Some implementations may offer their own API to do it. For example with DataNucleus if you go to this page http://www.datanucleus.org/products/accessplatform_3_0/jpa/persistence_unit.html at the end you can create dynamic persistence-units (and hence EMFs), and that implementation obviously allows persistence to the widest range of datastores you'll get anywhere
You can pass a Map of properties to createEntityManagerFactory() call that defines the database connection info, etc. The property names are the same as in the persistence.xml. I assume most JPA providers support this, EclipseLink does.
You will still need to define the set of classes for the database and map them.
If you do not have any classes either, than you could look into EclipseLink's dynamic support,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Dynamic
If you want to make a database browser accessing different databases, you can't use a PU/Entity Manager (imo).
You'll need a dialogue asking a user for the IP/Port of the database, the username/password, the database name to access, and the type of database.
Then all you need to do is create a socket, send requests over the socket, and parse the response into a view.
Since both the request and the response are database specific, the user has to select the proper database driver.

Java EE i18n without property files

normally I place my translations etc in properties - e.g. message_de.properties etc. I'm facing now a situation where I have to provide this data in a database. (Translations will be imported/edited in an other system)
Is there a common way/best practises to use a database table for messages in my webapp? One way I would thinking of was to build properties from the database but this seems not the right way to go.
A ResourceBundle doesn't need to be based on a properties file, you can write your own implementation and back them with JDBC or whatever tickles your fancy. The ResourceBundle javadoc page has an example on how to make a custom implementation.
To me it sounds like exporting the database to properties files would be the correct way to go. It's simple and I would assume the database does not change that often? The export can then be automated different ways.

Java: How do you use key/value datastores like memcached with Java property file code?

We are trying to move away from property files as files on the file system and more want to use a server based key/value store.
Does anyone have any code to do this with Java. Are there systems already built to connect to a server like memcached and build a property object with key values?
I want to do this in a struts web based project and a wicket web based project.
Have a look at commons-configuration which offers tons (well almost) ways to load and save config data.
The memcached wiki lists a handful of Java clients.

Categories

Resources