本文整理汇总了Java中java.sql.DataTruncation类的典型用法代码示例。如果您正苦于以下问题:Java DataTruncation类的具体用法?Java DataTruncation怎么用?Java DataTruncation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataTruncation类属于java.sql包,在下文中一共展示了DataTruncation类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug3804
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Tests fix for BUG#3804, data truncation on server should throw
* DataTruncation exception.
*
* @throws Exception
* if the test fails
*/
public void testBug3804() throws Exception {
if (versionMeetsMinimum(4, 1)) {
try {
this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3804");
this.stmt.executeUpdate("CREATE TABLE testBug3804 (field1 VARCHAR(5))");
boolean caughtTruncation = false;
try {
this.stmt.executeUpdate("INSERT INTO testBug3804 VALUES ('1234567')");
} catch (DataTruncation truncationEx) {
caughtTruncation = true;
System.out.println(truncationEx);
}
assertTrue("Data truncation exception should've been thrown", caughtTruncation);
} finally {
this.stmt.executeUpdate("DROP TABLE IF EXISTS testBug3804");
}
}
}
示例2: test
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Create DataTruncation object indicating a truncation on read
*/
@Test
public void test() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
示例3: test1
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Create DataTruncation object indicating a truncation on write
*/
@Test
public void test1() {
onRead = false;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(WRITE_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
示例4: test2
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Create DataTruncation object indicating a truncation on read with a
* Throwable
*/
@Test
public void test2() {
onRead = true;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& cause.equals(e.getCause().toString())
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
示例5: test3
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Create DataTruncation object indicating a truncation on read with null
* specified for the Throwable
*/
@Test
public void test3() {
onRead = true;;
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, null);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
示例6: test4
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Create DataTruncation object indicating a truncation on read and you can
* pass a -1 for the index
*/
@Test
public void test4() {
onRead = true;
int negIndex = -1;
DataTruncation e = new DataTruncation(negIndex, parameter, onRead,
dataSize, transferSize);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == negIndex);
}
示例7: test5
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Serialize a DataTruncation and make sure you can read it back properly
*/
@Test
public void test5() throws Exception {
DataTruncation e = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
DataTruncation ex1 = createSerializedException(e);
assertTrue(e.getMessage().equals(dtReason)
&& e.getSQLState().equals(READ_TRUNCATION)
&& e.getCause() == null
&& e.getErrorCode() == dterrorCode
&& e.getParameter() == parameter
&& e.getRead() == onRead
&& e.getDataSize() == dataSize
&& e.getTransferSize() == transferSize
&& e.getIndex() == index);
}
示例8: test11
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Validate that the ordering of the returned Exceptions is correct using
* for-each loop
*/
@Test
public void test11() {
DataTruncation ex = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t1);
DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
for (Throwable e : ex) {
assertTrue(dtmsgs[num++].equals(e.getMessage()));
}
}
示例9: test12
import java.sql.DataTruncation; //导入依赖的package包/类
/**
* Validate that the ordering of the returned Exceptions is correct using
* traditional while loop
*/
@Test
public void test12() {
DataTruncation ex = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t1);
DataTruncation ex1 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize);
DataTruncation ex2 = new DataTruncation(index, parameter, onRead,
dataSize, transferSize, t2);
ex.setNextException(ex1);
ex.setNextException(ex2);
int num = 0;
SQLException sqe = ex;
while (sqe != null) {
assertTrue(dtmsgs[num++].equals(sqe.getMessage()));
Throwable c = sqe.getCause();
while (c != null) {
assertTrue(dtmsgs[num++].equals(c.getMessage()));
c = c.getCause();
}
sqe = sqe.getNextException();
}
}