`
hlbng
  • 浏览: 175044 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
文章列表
Abstract Developers are frequently advised to read existing high-quality code. Having easy access to the Eclipse sources can be extremely helpful in familiarizing yourself with the coding patterns inherent in Eclipse. This article describes how to access the Eclipse source code, how to use th ...
package com.mengya.TestIO; import java.io.BufferedInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.FileOutputStream; import java.io.FileInputStream; import java.io.BufferedOutputStream; import java.io.FileWriter; import java ...
HibernateTemplate提供非常多的常用方法来完成基本的操作,比如通常的增加、删除、修改、查询等操作,Spring 2.0更增加对命名SQL查询的支持,也增加对分页的支持。大部分情况下,使用Hibernate的常规用法,就可完成大多数DAO对象的CRUD操作。下面是HibernateTemplate的常用方法简介: q void delete(Object entity):删除指定持久化实例 q deleteAll(Collection entities):删除集合内全部持久化类实例 q find(String queryString): ...
/** * 使用Criteria全查询 */ public List getallbyCriteria(){ List arr=null; try { Criteria cri=this.GetSession().createCriteria(Stu.class); arr=cri.list(); } catch (HibernateException e) { throw e; }finally{ this.CloseSession(); } return arr; } /** * 根据对象 ...
/** * 添加 */ public void save(Stu stu){ try { tran=this.GetSession().beginTransaction(); this.GetSession().save(stu); tran.commit(); } catch (HibernateException e) { throw e; }finally{ this.CloseSession(); } } /** * 使用HQL全查询 */ public List getallbyHQL ...
//JDBC操作大的文本数据是通过IO字符流操作 public class ClobTest { public static void main(String[] args) throws SQLException, IOException { // create(); read(); } 查询: static void read() throws SQLException, IOException { Connection conn = null; ...
//JDBC操作二进制类型数据(如图片或压缩包)也是通过IO字节流形式操作 public class BlobTest { public static void main(String[] args) throws SQLException, IOException { // create(); read(); } //查询 static void read() throws SQLException, IOException { Connection conn = ...
CallableStatement(从PreperedStatement扩展来) cs = connection.prepareCall(“{call psname(?,?,?)}”); cs.registerOutParameter(index, Types.INTEGER);//注册存储过程的输出参数 cs.setXXX(i, xxxx); cs.executeUpdate(); int id=cs.getInt(index);//得到存储过程的输出参数 public class PsTest { public static void ...
JDBC中的事务保存点,即事务发生回滚的时候,回滚到保存点那里去,事务开始到保存点之间的操作不用回滚. 事务(SavePoint) l 当只想撤销事务中的部分操作时可使用SavePoint l SavePoint sp = connection.setSavepoint(); l connection.rollerbak(sp); //回滚到那个事务点上去 l connection.commit(); import java.sql.Connection; import java.sql.Resu ...

DAO工厂模式

    博客分类:
  • JDBC
首先在src下面新建一个配置文件daoconfig.properites 内容如下:userDaoClass=com.mengya.dao.impl.UserDaoJdbcImpl DaoFactory类的内容如下: public class DaoFactory { private static UserDao userDao = null; //UserDao是UserDaoJdbcImpl的接口 private static DaoFactory instance = new DaoFactory(); pri ...
import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Date; public class DateTest { public static void main(String[] args) throws SQLException { // cre ...

JDBC简述

    博客分类:
  • JDBC
JDBC(Java Data Base Connectivity,java数据库连接),由一些接口和类构成的API。 J2SE的一部分,由java.sql,javax.sql包组成。 连接数据的步骤 l 注册驱动 (只做一次) 1,Class.forName(“com.mysql.jdbc.Driver”);   推荐这种方式,不会对具体的驱动类产生依赖。
package com.mengya.dao; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.hibernate.Criteria; import org.hibernate.HibernateException; import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.Transaction; import org.hibernate. ...
// 定义二维数组写法1 class numthree { public static void main(String[] args) { float[][] numthree; // 定义一个float类型的2维数组 numthree = new float[5][5]; // 为它分配5行5列的空间大小 numthree[0][0] = 1.1f; // 通过下标索引去访问 1行1列=1.1 numthree[1][0] = 1.2f; // 2行1列=1.2 numthree[2][0] = 1.3f; // 3行1列=1.3 numthree[ ...
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework ...
Global site tag (gtag.js) - Google Analytics