package impl;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import db.DBConnection;
import entity.Student;
public class StudentImpl {
public String joinString(String[] slikes){
String joinslikes="";
for(String temp:slikes){
joinslikes+=temp+"-";
}
System.out.println(joinslikes.substring(0, joinslikes.length()-1));
return joinslikes.substring(0, joinslikes.length()-1);
}
public void saveStudent(Student student) throws Exception {
// 连接数据库,完成数据的录入操作
//System.out.println("---saveStudent---");
DBConnection db=new DBConnection();
String sql="insert into student (sname,slikes,saddress) values (?,?,?)";
try {
PreparedStatement preStmt=db.getConn().prepareStatement(sql);
preStmt.setString(1, student.getSname());
preStmt.setString(2, student.getSlikes());
preStmt.setString(3, student.getSaddress());
preStmt.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}