⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdaoimpl.java

📁 LOGIN是由WEBWORK,AJAX,HIBERNATE,MYSQL等技术实现的一个LOGIN功能的网站,麻雀虽小,五脏俱全,绝对原创.
💻 JAVA
字号:
package com.gc.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


import com.gc.vo.Test;
import com.gc.dao.TestDAO;
import org.hibernate.Session;


import com.gd.jdbc.impl.GdDbCommon;

public class TestDAOImpl extends GdDbCommon implements TestDAO {
	private Connection con;
	private Session sess = null;

	public TestDAOImpl(Connection conn,Session session) {
		super(conn);
		con = conn;
		sess = session;

	}

	public int createTest(Test user) throws SQLException{
		String sql = "insert into test (username, password) values(?, ?)";
		this.PreparedStatement(sql);
		this.setString(1, user.getUsername());
		this.setString(2, user.getPassword());
		return this.executeUpdate();
	}
	
	public int updateTest(Test user) throws SQLException {
		String sql = "update test set password = ? where username = ? ";
		this.PreparedStatement(sql);
		this.setString(1, user.getPassword());
		this.setString(2, user.getUsername());
		return this.executeUpdate();
	}

	public int deleteTest(Test user)  throws SQLException{
		String sql = "delete from test where username = ?";
		this.PreparedStatement(sql);
		this.setString(1, user.getUsername());
		return this.executeUpdate();
	}
	
	public List  queryTest(String name) throws SQLException{
		List resultList = new ArrayList();
		Test result =new Test();
		String sql = "Select * from test where username = :username";
		//sql +="'"+name+"'";
		/*Statement stat = con.createStatement();
		
		 ResultSet re = stat.executeQuery(sql);
	     while(re.next()){
	      result.setUsername(re.getString("username"));
	      result.setPassword(re.getString("password"));
	      resultList.add(result);
	       }
	       */
		
		resultList = sess.createSQLQuery(sql)
	    .addEntity("test",Test.class).setString("username", name)
	    .list();
		
		return resultList;
	}
	
	public int createListTest(List list) throws SQLException{
		String sql = "insert into test (username, password) values(?, ?)";
		this.PreparedStatement(sql);
		Test user = null;
		int counts = 0;
		for (int i = 0; list != null && list.size() > i; i++) {
			user = (Test)list.get(i);
			this.setString(1, user.getUsername());
			this.setString (2,user.getPassword());
			counts += this.executeUpdate();
		}
		
		return counts;
	}
	
	
	public int[] createBatchListTest(List list) throws SQLException{
		String sql = "insert into test (username, password) values(?, ?)";
		this.PreparedStatement(sql);
		Test user = null;
		int counts = 0;
		for (int i = 0; list != null && list.size() > i; i++) {
			user = (Test)list.get(i);
			this.setString(1, user.getUsername());
			this.setString (2,user.getPassword());
			this.addBatch();
		}
		return this.executeBatch();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -