📄 datasourcepopulator.java
字号:
/* * Copyright 2004 original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.extremesite.dao;import org.springframework.beans.factory.InitializingBean;import org.springframework.jdbc.core.JdbcTemplate;/** * @author Jeff Johnston */public class DataSourcePopulator implements InitializingBean { JdbcTemplate jdbcTemplate; public void afterPropertiesSet() throws Exception { jdbcTemplate.execute("CREATE TABLE presidents ( " + " president_id INTEGER NOT NULL PRIMARY KEY, " + " first_name VARCHAR(50) NOT NULL, " + " last_name VARCHAR(50) NOT NULL, " + " nick_name VARCHAR(50) NOT NULL, " + " term VARCHAR(50) NOT NULL, " + " born DATE NOT NULL," + " died DATE NULL, " + " education VARCHAR(100) NULL, " + " career VARCHAR(100) NOT NULL, " + " political_party VARCHAR(100) NOT NULL " + " )"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(1, 'George', 'Washington', 'Father of His Country', '1789-1797', '1732-02-22 00:00:00.0', '1799-12-14 00:00:00.0', 'The equivalent of an elementary school education', 'Soldier, Planter', 'Federalist')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(2, 'John', 'Adams', 'Atlas of Independence', '1797-1801', '1764-10-25 00:00:00.0', '1826-07-04 00:00:00.0', 'Harvard College (graduated 1755)', 'Lawyer', 'Federalist')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(3, 'Thomas', 'Jefferson', 'Man of the People, Sage of Monticello', '1801-09', '1743-04-13 00:00:00.0', '1826-07-04 00:00:00.0', 'College of William and Mary (graduated 1762)', 'Lawyer, Planter', 'Democratic-Republican ')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(4, 'James', 'Madison', 'Father of the Constitution', '1809-17', '1751-03-16 00:00:00.0', '1836-06-28 00:00:00.0', 'College of New Jersey (now Princeton University, graduated 1771)', 'Lawyer', 'Democratic-Republican')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(5, 'James', 'Monroe', 'The Last Cocked Hat, Era-of-Good-Feelings President', '1817-25', '1758-04-28 00:00:00.0', '1831-07-04 00:00:00.0', 'College of William and Mary (graduated 1776)', 'Lawyer', 'Democratic-Republican')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(6, 'John', 'Adams', 'Old Man Eloquent', '1825-29', '1767-07-11 00:00:00.0', '1848-02-23 00:00:00.0', 'Harvard College (graduated 1787)', 'Lawyer, Senator, Diplomat', 'Federalist, Democratic-Republican, Whig ')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(7, 'Andrew', 'Jackson', 'Old Hickory', '1829-37', '1767-03-15 00:00:00.0', '1845-06-08 00:00:00.0', '', 'Lawyer, Soldier', 'Democrat')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(8, 'Martin', 'Van Buren', 'The Little Magician, The Red Fox of Kinderhook', '1837-41', '1782-12-05 00:00:00.0', '1862-08-24 00:00:00.0', 'Kinderhook Academy (graduated 1796)', 'Lawyer', 'Democrat')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(9, 'William Henry', 'Harrison', 'Old Tippecanoe, Old Tip', '1841', '1773-02-09 00:00:00.0', '1841-05-04 00:00:00.0', 'Hampden-Sydney College', 'Soldier', 'Whig')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(10, 'John', 'Tyler', 'Accidental President, His Accidency', '1841-45', '1790-03-29 00:00:00.0', '1862-01-18 00:00:00.0', 'College of William and Mary (graduated 1807)', 'Lawyer', 'Democrat, Whig')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(11, 'James', 'Polk', 'Young Hickory', '1845-49', '1795-11-02 00:00:00.0', '1849-06-15 00:00:00.0', 'University of North Carolina (graduated 1818)', 'Lawyer', 'Democrat')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(12, 'Zachary', 'Taylor', 'Old Rough and Ready', '1849-50', '1810-06-21 00:00:00.0', '1850-07-09 00:00:00.0', '', 'Soldier', 'Whig')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(13, 'Millard', 'Fillmore', 'The American Louis Philippe', '1850-53', '1800-01-07 00:00:00.0', '1874-03-08 00:00:00.0', 'Six months of grade school; read law in 1822', 'Lawyer', 'Whig')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(14, 'Franklin', 'Pierce', 'Young Hickory of the Granite Hills', '1853-57', '1804-11-23 00:00:00.0', '1869-10-08 00:00:00.0', 'Bowdoin College (graduated 1824)', 'Lawyer, Public Official', 'Democrat')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(15, 'James', 'Buchanan', 'Old Buck', '1857-61', '1791-05-23 00:00:00.0', '1868-06-01 00:00:00.0', 'Dickinson College (graduated 1809)', 'Lawyer', 'Democrat')"); jdbcTemplate.execute("INSERT INTO presidents(president_id, first_name, last_name, nick_name, term, born, died, education, career, political_party)" + " VALUES(16, 'Abraham', 'Lincoln', 'Honest Abe, Illinois Rail-Splitter', '1861-65', '1809-02-12 00:00:00.0', '1865-05-15 00:00:00.0', '', 'Lawyer', 'Whig, Republican')");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -