공용 클래스 OrderTest {
개인 문자열 드라이버 = "com.mysql.jdbc.Driver";
개인 문자열 URL = "JDBC한다 : mysql : // localhost를 : 3306 / OS useUnicode = TRUE & characterEncoding = UTF8";
개인 문자열의 userName = "루트";
개인 문자열 암호 = "루트";
@Test
공공 무효 addOrder () {
시도 {
Class.forName을 (드라이버);
} 캐치 (ClassNotFoundException가 전자) {
e.printStackTrace ();
}
연결 접속 = NULL;
{시도
연결 = DriverManager.getConnection를 (URL, 사용자 이름, 암호);
connection.setAutoCommit (FALSE);
문 문 = 항목 : Connection.createStatement () ;
의 Statement.execute ( "(주문 값으로 지금은 '100002', '100001', 2,2499를, (삽입), NULL, NULL, '刘备', '1330000000', '成都', '待发货')") ;
의 Statement.execute는 ( "업데이트 제품은 STCK 설정 = 주식이 어디 ID = '100001'");
connection.commit ();
} 캐치 (예외 : SQLException 전자) {
e.printStackTrace ();
{시도
) (connection.rollback을;
} 캐치 (E1의 SQLException) {
e1.printStackTrace ();
}
} 마지막으로 {
{시도
) (의 Connection.close를;
} 캐치 (예외 : SQLException 전자) {
e.printStackTrace ();
}
}
}
}