I’ve just started with Vaadin and done the vaadin tutorial and working on my first solo project as a test. Trying to create a simple form where you can input data and save it to a database. Problem is I have no clue on how to connect to a database with Vaadin. Any helpful link where I could read about it ? Specifically I want to connect to a MS SQL 2005 database server.
I’ve got a connection up and running and was able to execute queries.
Thanks for pointing me at the right direction. I’m a bit rusty with Java in general haven’t used it for a few years.
Specifically I’m using MS SQL 2005 server and maybe in the future 2008 or whatever comes after that. I ended up setting it up using:
Microsoft SQL Server JDBC Driver http://msdn.microsoft.com/en-us/data/aa937724.aspx with the documentation that came with the driver I got things up and running.
Any reason why you suggest JPA ? Should I try in the future use that instead of JDBC ? I’m afraid I don’t understand enough to compare them or even enough if the two can be compared.
Using Object Relational Mapping you get things done a lot faster. It has performance issues is used wrong (example fetching too much stuff too early or using inefficient queries) but so does plain sql through jdbc.
As a basic example inserting new “row” to person-table using JPA:
Person p = new Person();
p.setName("name");
entityManager.persist(p);
Example: you need to get persons jobs:
person.getJobs();
And jpa-provider does all the sql’s in the background.
Mapping Person using annotations:
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.TABLE)
private String id;
private String name;
@OneToMany
private List<Job> jobList = new ArrayList<Job>();
public String getId() {
return id;
}
public void setId(String Id) {
this.id = Id;
}
public String geName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Job> getJobs() {
return this.jobs;
}
public void setJobs(List<Job> jobs) {
this.jobs = jobs;
}
}