public class TestMain {
- static Logger logger = Logger.getLogger(TestMain.class);
+ private static final Logger logger = Logger.getLogger(TestMain.class);
public static void main(final String[] args) throws IOException {
.build(/**TestMain.class.getResourceAsStream("sql-maps-config.xml")**/
Resources.getResourceAsStream("mybatis-sql-maps-config.xml"), "mybatisexample");
- final SqlSession session = sqlSessionFactory.openSession();
+ SqlSession session = sqlSessionFactory.openSession();
try {
final AdMapper adMapper = session.getMapper(AdMapper.class);
final Ad adTest = new Ad();
- adTest.setAdMobileImage("lol");
+ adTest.setAdMobileImage("mobileImage.jpg");
adTest.setCompanyCategId(200L);
adTest.setCreatedAt(new Date());
adTest.setCompanyId(2L);
logger.info("Ad GPS: " + new String(ad.getAdGps(), "UTF-8"));
}
logger.info("Ad mobileImage: " + ad.getAdMobileImage());
- logger.info("Ad mobileImage: " + ad.getCompanyCategId());
- logger.info("Ad id: " + ad.getCompanyId());
- logger.info("Ad id: " + ad.getCreatedAt());
- logger.info("Ad id: " + ad.getUpdatedAt());
+ logger.info("Ad companyCategId: " + ad.getCompanyCategId());
+ logger.info("Ad companyId: " + ad.getCompanyId());
+ logger.info("Ad createdAt: " + ad.getCreatedAt());
+ logger.info("Ad updatedAt: " + ad.getUpdatedAt());
logger.info("\n");
}
+ } finally {
+ session.close();
+ }
+
+ session = sqlSessionFactory.openSession();
+
+ try {
+ logger.info("Last insert");
+ final AdMapper adMapper = session.getMapper(AdMapper.class);
+ final Ad adTest = new Ad();
+ adTest.setAdMobileImage("mobileImage.jpg");
+ adTest.setCompanyCategId(200L);
+ adTest.setCreatedAt(new Date());
+ adTest.setCompanyId(2L);
+ adTest.setUpdatedAt(new Date());
+ adMapper.insert(adTest);
+ session.commit();
} finally {
session.close();
<property name="suppressDate" value="true" />
</commentGenerator>
+ <!--
+ If you are dropping like me (by means of some firewall) IPV6 connections and you feel
+ during the first MySLQ connection as if there is a huge lag and you are using
+ *NIX, you could use this system property -Djava.net.preferIPv4Stack=true
+ in order to stop using IPV6 from JVM.
+ -->
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/mybatis_example?characterEncoding=UTF-8" userId="root" password="root">
</jdbcConnection>
<transactionManager type="JDBC"/>
<dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
+ <!--
+ If you are dropping like me (by means of some firewall) IPV6 connections and you feel
+ during the first MySLQ connection as if there is a huge lag and you are using
+ *NIX, you could use this system property -Djava.net.preferIPv4Stack=true
+ in order to stop using IPV6 from JVM.
+ -->
<property name="url" value="jdbc:mysql://localhost:3306/mybatis_example?characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="root"/>