Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Database connection with vaadin
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.
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.
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 .
public class Main
public static void main(arg)
Class.forName("postgre driver name");
Connection con = DriverManager.getConnection("dbname","username","pwd");
//your business logic goes here....
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.
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.
Kim Leppänen: 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.
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....