Package tester.business.maitain;
import Tclcc.tester.business.maitain.Trainplan;
import Tclcc.tester.util.DBConn;
import java.sql.*;
import java.util.*;
public class Trainplandao {
private Dbconn dbconn = null;
private Connection conn = null;
private static final String add_trainplan=
"INSERT into Ks_trainplan (p_id,p_title,issue_time,issuer,p_content,p_accessory) VALUES (Lpad (Seq_p_id.nextval, 10,´0´),?,?, to_date (?, ´yyyy-mm-dd´),?,?,?) ";
private final static String update_trainplan=
"UPDATE Ks_trainplan set P_id=?,p_title=?,post_index=?,issue_time=to_date (?, ´yyyy-mm-dd´), issuer=?,p_content= ?, p_accessory=? where p_id=? ";
/**
* Get a connection a DB pool
* @return Connection
*/
public Trainplandao () {
try {
dbconn = new Dbconn ();
conn = Dbconn.getconnection ();
} catch (Exception ex) {
Ex.printstacktrace ();
}
}
/**
* Add a row into DB
* @param examinee examinee
* @throws SQLException
*/
public void Addtrainplan (Trainplan Trainplan) throws SQLException {
PreparedStatement pstmt = null;
try {
pstmt = conn.preparestatement (Add_trainplan);
pstmt.setstring (1, Trainplan.getp_title ());
pstmt.setstring (2, Trainplan.getissue_time ());
pstmt.setstring (3, Trainplan.getissuer ());
pstmt.setstring (4, Trainplan.getp_content ());
pstmt.setstring (5, Trainplan.getp_accessory ());
pstmt.executeupdate ();
} catch (SQLException ex) {
Ex.printstacktrace ();
} finally {
try {
Pstmt.close ();
//conn.close ();
} catch (SQLException Ex1) {
}
}
}
/**
* Remove a row from DB
* @param trainplan Trainplan
* @throws SQLException
*/
public void Removetrainplan (Trainplan Trainplan) throws SQLException {
This.removetrainplan (trainplan.getp_id ());
}
/**
* Remove a row from DB
* @param p_id int
* @throws SQLException
*/
public void Removetrainplan (int p_id) throws SQLException {
Statement stmt = null;
try {
stmt = Conn.createstatement ();
Stmt.execute ("DELETE from Ks_trainplan WHERE p_id=" + p_id);
} catch (SQLException ex) {
Ex.printstacktrace ();
throw new SQLException ("Sqlexction On:TrainPlanDAO.removeExaminee ()");
} finally {
try {
Conn.close ();
} catch (SQLException Ex1) {
Ex1.printstacktrace ();
}
}
}
/**
* Update a row
* @param examinee examinee
* @throws SQLException
*/
public void Updatetrainplan (Trainplan Trainplan) throws SQLException {
PreparedStatement pstmt = null;
try {
//Update_trainplan = Update_trainplan + "where p_id =" + trainplan.getp_id (); The condition need modification
pstmt = conn.preparestatement (Update_trainplan);
pstmt.setint (1, trainplan.getp_id ());
pstmt.setstring (2, Trainplan.getp_title ());
Pstmt.setint (3, Trainplan.getpost_index ());
pstmt.setstring (4, Trainplan.getissue_time ());
pstmt.setstring (5, Trainplan.getissuer ());
pstmt.setstring (6, trainplan.getp_content ());
pstmt.setstring (7, Trainplan.getp_accessory ());
Pstmt.setint (8,trainplan.getp_id ());
pstmt.executeupdate ();
}/*catch (SQLException ex) {
Ex.getstacktrace ();
throw new SQLException ("Sqlexction On:TrainPlanDAO.updateExaminee ()");
} */
catch (SQLException Sqle) {
do
{
System.err.println ("Exception occoured:\nmessage:" +sqle.getmessage ());
System.err.println ("SQL State:" +sqle.getsqlstate ());
System.err.println ("Vendor Code:" +sqle.geterrorcode () + "\ n---------------");
} while ((Sqle=sqle.getnextexception ())!=null);
}finally {
try {
Conn.close ();
} catch (SQLException Ex1) {
Ex1.printstacktrace ();
}
}
}
/**
* Get all record from DB
* @throws SQLException
* @return Collection
*/
public Collection GetAll () throws SQLException {
Statement stmt = null;
ResultSet rs = null;
Trainplan Trainplan = null;
Collection list = null;
try {
stmt = Conn.createstatement ();
rs = stmt.executequery ("SELECT * from Ks_trainplan");
list = new ArrayList ();
while (Rs.next ()) {
Trainplan = new Trainplan ();
trainplan.setp_id (Rs.getint ("p_id"));
Trainplan.setp_title (rs.getstring ("P_title"));
Trainplan.setpost_index (Rs.getint ("Post_index"));
Trainplan.setissue_time (rs.getstring ("Issue_time"));
Trainplan.setissuer (rs.getstring ("issuer"));
trainplan.setp_content (rs.getstring ("p_content"));
trainplan.setp_accessory (rs.getstring ("p_accessory"));
List.add (Trainplan);
}
} catch (SQLException ex) {
} finally {
try {
Conn.close ();
} catch (SQLException Ex1) {
Ex1.printstacktrace ();
}
return list;
}
}
public static String toString (Trainplan trainplan) {
return Trainplan.getp_title ();
}
/**
* for Test
* @param args string[]
*/
}