| | 54 | * 准备tablename,我们可以在数据库中创建一张表,用来测试 |
| | 55 | |
| | 56 | {{{ #!java |
| | 57 | private void createTesttable(String table) { |
| | 58 | |
| | 59 | simpleJdbcTemplate.update("DROP TABLE IF EXISTS `" + table + "`"); |
| | 60 | |
| | 61 | simpleJdbcTemplate |
| | 62 | .update("CREATE TABLE `" + table + "` (" |
| | 63 | + "`id` bigint(20) NOT NULL," |
| | 64 | + "`createAt` timestamp NULL DEFAULT NULL," |
| | 65 | + "`name` varchar(50) DEFAULT NULL," |
| | 66 | + "`age` int(11) DEFAULT NULL," |
| | 67 | + "`info` text," |
| | 68 | + "`rate` float DEFAULT NULL," |
| | 69 | + "PRIMARY KEY (`id`)" |
| | 70 | + ") ENGINE=InnoDB DEFAULT CHARSET=gbk;"); |
| | 71 | |
| | 72 | Calendar calendar = Calendar.getInstance(); |
| | 73 | calendar.set(Calendar.YEAR, 2011); |
| | 74 | calendar.set(Calendar.MONTH, 10); |
| | 75 | calendar.set(Calendar.DAY_OF_MONTH, 10); |
| | 76 | calendar.set(Calendar.HOUR_OF_DAY, 23); |
| | 77 | calendar.set(Calendar.MINUTE, 23); |
| | 78 | calendar.set(Calendar.SECOND, 23); |
| | 79 | |
| | 80 | int rows = simpleJdbcTemplate.update( |
| | 81 | "INSERT INTO test_table VALUES(?,?,?,?,?,?)", new Object[] { |
| | 82 | 393648562, calendar.getTime(), "chenyang", 25, |
| | 83 | "速度第一,完美第二",0.35 }); |
| | 84 | |
| | 85 | Assert.assertEquals(1, rows); |
| | 86 | |
| | 87 | } |
| | 88 | }}} |