您好,欢迎光临本网站![请登录][注册会员]  
文件名称: iBatis-设置缓存模式-Java源码(下载)
  所属分类: 其它
  开发工具:
  文件大小: 919kb
  下载次数: 0
  上传时间: 2009-07-09
  提 供 者: tjgt*****
 详细说明: File: Account.xml insert into ACCOUNT ( ACC_ID, ACC_FIRST_NAME, ACC_LAST_NAME, ACC_EMAIL )values ( #id#, #firstName#, #lastName#, #emailAddress# ) File: Main.java import java.util.List; import com.ibatis.sqlmap.client.SqlMapClient; public class Main { public static void main(String[] a) throws Exception { Util util = new Util(); util .executeSQLCommand("create table ACCOUNT(ACC_ID int, ACC_FIRST_NAME varchar,ACC_LAST_NAME varchar,ACC_EMAIL varchar);"); util.executeSQLCommand("create table Message(Message_ID int, content varchar);"); SqlMapClient sqlMapper = util.getSqlMapClient(); Account account = new Account(); account.setId(1); account.setEmailAddress("e"); account.setFirstName("first"); account.setLastName("last"); sqlMapper.insert("insertAccount", account); util.checkData("select * from account"); List list = sqlMapper.queryForList("getByLike", account); System.out.println(((Account)list.get(0)).getLastName()); } } File: SqlMapConfig.xml File: Util.java import java.io.Reader; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; import com.ibatis.common.resources.Resources; import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClientBuilder; public class Util { Statement st; public Util() throws Exception{ // Load the JDBC driver. Class.forName("org.hsqldb.jdbcDriver"); System.out.println("Driver Loaded."); // Establish the connection to the database. String url = "jdbc:hsqldb:data/tutorial"; Connection conn = DriverManager.getConnection(url, "sa", ""); System.out.println("Got Connection."); st = conn.createStatement(); } public SqlMapClient getSqlMapClient() throws Exception{ Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml"); SqlMapClient sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); reader.close(); return sqlMapper; } public void executeSQLCommand(String sql) throws Exception { st.executeUpdate(sql); } public void checkData(String sql) throws Exception { ResultSet rs = st.executeQuery(sql); ResultSetMetaData metadata = rs.getMetaData(); for (int i = 0; i < metadata.getColumnCount(); i++) { System.out.print("\t"+ metadata.getColumnLabel(i + 1)); } System.out.println("\n----------------------------------"); while (rs.next()) { for (int i = 0; i < metadata.getColumnCount(); i++) { Object value = rs.getObject(i + 1); if (value == null) { System.out.print("\t "); } else { System.out.print("\t"+value.toString().trim()); } } System.out.println(""); } } } File: Account.java public class Account { private int id; private String firstName; private String lastName; private String emailAddress; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: iBatis 缓存
 输入关键字,在本站1000多万海量源码库中尽情搜索: