[Java]
Package com. qiyi. datatools;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. PreparedStatement;
Import java. SQL. ResultSet;
Import java. util. ArrayList;
Import junit. framework. TestCase;
Import org. junit. After;
Import org. junit. Before;
Import org. junit. Test;
Public class TableVoHelper extends TestCase {
@ Test
Public void testOp () throws Exception {
Pstmt = con. prepareStatement ("delete from tableB ");
Pstmt.exe cute ();
Pstmt = con. prepareStatement ("select * from tableA ");
Rs = pstmt.exe cuteQuery ();
ArrayList <TableVo> tVoList = new ArrayList <TableVo> ();
While (rs. next ()){
TableVo tVo = new TableVo ();
TVo. setId (rs. getInt (1 ));
TVoList. add (tVo );
}
Pstmt = con. prepareStatement ("insert into tableB (id) values (?) ");
For (TableVo tVo: tVoList ){
Pstmt. setInt (1, tVo. getId ());
Pstmt.exe cute ();
}
}
@ Before
Public void setUp () throws Exception {
String CLASSNAME = "com. mysql. jdbc. Driver ";
String URL = "jdbc: mysql: // localhost: 3306/fiona ";
String UNAME = "root ";
String PWD = "root ";
Class. forName (CLASSNAME );
Con = DriverManager. getConnection (URL, UNAME, PWD );
}
@ After
Public void tearDown () throws Exception {
If (rs! = Null ){
Rs. close ();
}
If (pstmt! = Null ){
Pstmt. close ();
}
If (con! = Null ){
Con. close ();
}
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Class TableVo {
Public int getId (){
Return id;
}
Public void setId (int id ){
This. id = id;
}
Private int id;
}
}
Package com. qiyi. datatools;
Import java. SQL. Connection;
Import java. SQL. DriverManager;
Import java. SQL. PreparedStatement;
Import java. SQL. ResultSet;
Import java. util. ArrayList;
Import junit. framework. TestCase;
Import org. junit. After;
Import org. junit. Before;
Import org. junit. Test;
Public class TableVoHelper extends TestCase {
@ Test
Public void testOp () throws Exception {
Pstmt = con. prepareStatement ("delete from tableB ");
Pstmt.exe cute ();
Pstmt = con. prepareStatement ("select * from tableA ");
Rs = pstmt.exe cuteQuery ();
ArrayList <TableVo> tVoList = new ArrayList <TableVo> ();
While (rs. next ()){
TableVo tVo = new TableVo ();
TVo. setId (rs. getInt (1 ));
TVoList. add (tVo );
}
Pstmt = con. prepareStatement ("insert into tableB (id) values (?) ");
For (TableVo tVo: tVoList ){
Pstmt. setInt (1, tVo. getId ());
Pstmt.exe cute ();
}
}
@ Before
Public void setUp () throws Exception {
String CLASSNAME = "com. mysql. jdbc. Driver ";
String URL = "jdbc: mysql: // localhost: 3306/fiona ";
String UNAME = "root ";
String PWD = "root ";
Class. forName (CLASSNAME );
Con = DriverManager. getConnection (URL, UNAME, PWD );
}
@ After www.2cto.com
Public void tearDown () throws Exception {
If (rs! = Null ){
Rs. close ();
}
If (pstmt! = Null ){
Pstmt. close ();
}
If (con! = Null ){
Con. close ();
}
}
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
Class TableVo {
Public int getId (){
Return id;
}
Public void setId (int id ){
This. id = id;
}
Private int id
}
}
Author: hongqishi