Database connection with vaadin

Hi

I am new user of vaadin framework. I want to connect the database from vaadin by using JDBC. But i don't have any clue that where i have to write the database connection code and where i have to execute the queries in database in vaadin application. Is it possible to write that in init() method of Application class? Please send me any sample example code to connect to the database from a vaadin application as early as possible.My database is PostgreSql.
                         Thank you in advance.

Hi,

maybe this will help you:

connecting to PostgreSQL with vaadin

Regards,
Thorsten

If you don’t write any custom widgets, then all the java code you will be writing is executed on the server side, meaning you can connect to a database from any of your server side classes, including the Application class.

Hi

For connecting java with Postgresql database you need postgresql jar file(like mysql j connector). Here below i attached jar file or you can download it by http://jdbc.postgresql.org/download.html latest jar file , you can use it. below is sample code .

Main.java

public class Main
{
public static void main(arg)
{
try
{
Class.forName(“postgre driver name”);
Connection con = DriverManager.getConnection(“dbname”,“username”,“pwd”);
//your business logic goes here…

     }catch(SQLException e){System.out.print(e);}
}

}

you can check whether connection is established or not. This is very simple code for every database connection like jdbc,mysql,etc.

you can use this code in your vaadin application surrounded with try catch. thats it.

Note :
If you using netbeans ide, you just can copy paste this postgre sql jar into C:\Program Files\Java\jdk1.6.0_21\jre\lib\ext or using text editor you can paste in C:\Program Files\Java\jre6\lib\ext.(if you done this you need not to use Class.forName(“driver name”); for loading driver name. JRE will locate the specified driver) or you can add this jar into your class path of your application.
11526.jar (527 KB)

Hi ,

        Now i am working on integration of gwt widgets into vaadin, it works fine but i want to connect database through gwt widgets in vaadin where i have to put my data base code please send me any sample example. very urgent....