用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

基于Xutils3的android开发

2018-05-25 作者: 云代码会员举报

[android]代码库

(1)Dao类
package org.gdufs.dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import org.gdufs.entity.Student;
import org.gdufs.util.DBHelper;
import org.gdufs.util.DBHelper2;
public class StudentDao {
	public Student findStudentById(String studentId) {
		Student student = null;
		Connection con = null;
		PreparedStatement stat = null;
		con = DBHelper2.connect();
		String sql1 = "select * from student where studentId=?";// and password=?";
		try {
			stat = con.prepareStatement(sql1);
			stat.setString(1, studentId);
			ResultSet rs = stat.executeQuery();
			if (rs.next()) {
				student = new Student();
				student.setStudentId(studentId);
				student.setStudentName(rs.getString("studentName"));
				student.setPassword(rs.getString("password"));
				student.setClassName(rs.getString("className"));
				student.setEmail(rs.getString("email"));
				student.setPhoto(rs.getString("photo"));
				student.setTelephone(rs.getString("telephone"));
				student.setSex(rs.getString("sex"));
				student.setSchool(rs.getString("school"));
			}
		} catch (SQLException ex) {
			System.out.println("dao异常"+ex.toString());
		} finally {
			DBHelper2.closePreparedStatement(stat);
			DBHelper2.closeConneciton(con);
		}
		return student;
	}

 public List<Student> getStudents() {
		List<Student> students = new ArrayList<Student>();
		Student student = null;
		Connection con = null;
		PreparedStatement stat = null;
		con = DBHelper2.connect();
		String sql1 = "select * from student ";// and password=?";
		try {
			stat = con.prepareStatement(sql1);
			ResultSet rs = stat.executeQuery();
			while (rs.next()) {
				student = new Student();
				student.setStudentId(rs.getString("studentId"));
				student.setStudentName(rs.getString("studentName"));
				student.setPassword(rs.getString("password"));
				student.setClassName(rs.getString("className"));
				student.setEmail(rs.getString("email"));
				student.setPhoto(rs.getString("photo"));
				student.setTelephone(rs.getString("telephone"));
				student.setSex(rs.getString("sex"));
				student.setSchool(rs.getString("school"));
				students.add(student);
			}
		} catch (SQLException ex) {
			System.out.println("dao异常" + ex.toString());
		} finally {
			DBHelper2.closePreparedStatement(stat);
			DBHelper2.closeConneciton(con);
		}
		return students;
	}
}

[源代码打包下载]




网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...