/** * @ Author Hu Ronghua * @ Company Century dragon 21cn */ Package com. cjdbc. test; Import java. SQL. connection; Import java. SQL. preparedstatement; Import java. SQL. drivermanager; /** * */ Public class generatesampledata { Public void generate () { connection conn = NULL; preparedstatement pstmt = NULL; try { // This is the drivers class of C-JDBC drivers, note that it is not mysql drivers class class. forname ("org. objectweb. cjdb C. driver. driver "). newinstance (); // 192.168.0.1 is the IP address of the cjdbc controller // mydb is defined in the file mysql-raidb1-distribution.xml // user = boss & Password = boss is defined in the file mysql-raidb1-distribution.xml // // // string url = "JDBC: cjdbc: // 192.168.0.1: 25323/mydb? User = boss & Password = boss "; Conn = drivermanager. getconnection (URL ); Try { Conn. setautocommit (false ); Pstmt = conn. preparestatement ("insert into user values ('',?) "); Int numoftestrecords = 10; System. Out. println ("Update record start ."); For (INT I = 0; I <numoftestrecords; I ++ ){ String newkey = I + "-" + I; Pstmt. setstring (1, "Hua _" + newkey ); Pstmt.exe cuteupdate (); } Conn. Commit (); System. Out. println ("Update record success ."); } Catch (exception ex ){ Conn. rollback (); Ex. printstacktrace (); } Finally { Try { If (pstmt! = NULL) Pstmt. Close (); If (Conn! = NULL) Conn. Close (); } Catch (exception e ){ E. printstacktrace (); } } } Catch (exception e ){ E. printstacktrace (); } } /** * @ Param ARGs */ Public static void main (string [] ARGs ){ // Todo auto-generated method stub Generatesampledata G = new generatesampledata (); G. Generate (); } } |