database class uncomplete

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;


public class Student_oprate {


PreparedStatement pst;
Connection con;
public Connection getConn() throws ClassNotFoundException, SQLException
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydata?useUnicode=true&characterEncoding=utf-8", "root", "");
return con;
}

public int  addstu(Student stu) throws ClassNotFoundException, SQLException
{
con = getConn();
String sql_in = "insert into student values(null, ?, ?)";
PreparedStatement pst = con.prepareStatement(sql_in);
pst.setString(1, stu.getName());
pst.setInt(2, stu.getAge());
int exi = pst.executeUpdate();
pst.close();
con.close();
return exi;
}

public int delstu(int id)
{

}
//update
//select all
//select by key
}

猜你喜欢

转载自blog.csdn.net/shadowam/article/details/80048623