save的时候如果name存入的是中文,那编码问题怎么解决?
这是创建学生的实现:
@Override public void create(Student student) { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; String sql = "insert into student (name, age) values (?,?)"; try { connection = JDBCUtil.getConnection(); preparedStatement = connection.prepareStatement(sql); preparedStatement.setString(1, student.getName()); preparedStatement.setInt(2, student.getAge()); preparedStatement.executeUpdate(); } catch (Exception e) { e.printStackTrace(); } finally { JDBCUtil.release(resultSet, preparedStatement, connection); } }
这是单元测试:
@Test public void create() { StudentDAO studentDAO = new StudentDAOImpl(); Student student = new Student(); student.setName("赵六"); student.setAge(26); studentDAO.create(student); }