First of all you will need a database connector. You canget it from your database's official website. Let's for example use MySQL
database.
You can get the connector here:
https://web.archive.org/web/20130920121513/http://dev.mysql.com/usingmysql/java/You next step will be creating SQL tables for yourentities (bookings), where all the data is represented by plain text (Strings,
numeric types, Date type e.t.c.) The method you execute transactions to
database vary from language to language. Here's a java example:
import java.sql.*;
class Example{
private Connection connection;
public voidinit() {
Properties p =new Properties();
//user and password are set in your db configuration
p.setProperty("user", "root");
p.setProperty("password", "pwd");
try {
Class.forName("org.gjt.mm.mysql.Driver");
} catch (ClassNotFoundException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}
StringconnectionURL = "jdbc:mysql://localhost/yourDatabaseName";
try {
connection= DriverManager.getConnection(connectionURL, p);
} catch(SQLException e) {
// TODOAuto-generated catch block
e.printStackTrace();
}
}
}
And that's it. You can use 'connection' object anywhereExecuting SQL statements:
PreparedStatement ps = null;
String sql = "SELECT * FROM userdata WHEREusername=?";
ps =connection.prepareStatement(sql);
ps.executeQuery();
That's all the basics
Comments
Leave a comment