重要语句
pstm.setString(4,String.valueOf(你的char));
完整代码示例
- package com.yzk.student.dao;
-
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
-
- import com.yzk.student.model.Student;
- import com.yzk.student.util.JdbcUtils;
-
- public class StudentDao {
- static Connection conn=null;
- static PreparedStatement pstm= null;
- public static void main(String[] args) throws Exception {
- StudentDao studentDao = new StudentDao();
- Student student = new Student(21, "小米", "root1234", 18, '男', "Java");
- studentDao.Up(student);
- }
- public void Up(Student student)
- {
- try {
- conn = JdbcUtils.getconnection();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- String sql="update student set name=?,password=?,age=?,gender=?,classs=? where id=?";
- try {
- pstm = conn.prepareStatement(sql);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- pstm.setString(1, student.getName());
- pstm.setString(2, student.getPassword());
- pstm.setInt(3,student.getAge());
- pstm.setString(4,String.valueOf(student.getGender()));
- pstm.setString(5, student.getClasss());
- pstm.setInt(6, 21);
- pstm.executeUpdate();
- JdbcUtils.release( null,pstm, conn);
- System.out.println(conn);
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
- }