ForumDAO
package dao.jdbc;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
public class ForumDAO extends JdbcDaoSupport
{
public void initDb()
{
String sql = "create table t_user1(user_id int primary key,user_name varchar(60))";
getJdbcTemplate().execute(sql);
}
}
Main
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
public class Main
{
public static void main(String args[])
{
DriverManagerDataSource ds = new DriverManagerDataSource();
ds.setDriverClassName("com.mysql.jdbc.Driver");
ds.setUrl("jdbc:mysql://localhost:3306/sampledb");
ds.setUsername("root");
ds.setPassword("");
JdbcTemplate jdbc = new JdbcTemplate();
jdbc.setDataSource(ds);
String sql = "create table t_user1(user_id int primary key,user_name varchar(60))";
jdbc.execute(sql);
}