📄 timestamptest.java
字号:
new byte[] {
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
} },
*/
{ "float(6)", "65.4321", new BigDecimal("65.4321") },
{ "binary(5)", "0x1213141516", new byte[] { 0x12, 0x13, 0x14, 0x15, 0x16 } },
{ "varbinary(4)", "0x1718191A", new byte[] { 0x17, 0x18, 0x19, 0x1A } },
{ "varchar(8)", "'12345678'", new String("12345678") },
{ "datetime", "'19990815 21:29:59.01'", Timestamp.valueOf("1999-08-15 21:29:59.01") },
{ "smalldatetime", "'19990215 20:45'", Timestamp.valueOf("1999-02-15 20:45:00") },
{ "float(6)", "65.4321", new Float(65.4321)/* new BigDecimal("65.4321") */},
{ "float(14)", "1.123456789", new Double(1.123456789) /*new BigDecimal("1.123456789") */},
{ "real", "7654321.0", new Double(7654321.0) },
{ "int", "4097", new Integer(4097) },
{ "float(6)", "65.4321", new BigDecimal("65.4321") },
{ "float(14)", "1.123456789", new BigDecimal("1.123456789") },
{ "decimal(10,3)", "1234567.089", new BigDecimal("1234567.089") },
{ "numeric(5,4)", "1.2345", new BigDecimal("1.2345") },
{ "smallint", "4094", new Short((short)4094) },
// { "tinyint", "127", new Byte((byte)127) },
// { "tinyint", "-128", new Byte((byte)-128) },
{ "smallint", "127", new Byte((byte)127) },
{ "smallint", "-128", new Byte((byte)-128) },
{ "money", "19.95", new BigDecimal("19.95") },
{ "smallmoney", "9.97", new BigDecimal("9.97") },
{ "bit", "1", Boolean.TRUE },
// { "text", "'abcedefg'", new String("abcdefg") },
/* { "char(1000)",
"'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'",
new String("123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890") },
*/
// { "char(1000)", "'1234567890'", new String("1234567890") },
{ "image", "0x0a0a0b", new byte[] { 0x0a, 0x0a, 0x0b } },
};
}
public void testOutputParams() throws Exception
{
Statement stmt = con.createStatement();
dropProcedure("#jtds_outputTest");
Object[][] datatypes = getDatatypes();
for (int i = 0; i < datatypes.length; i++)
{
String valueToAssign;
boolean bImage = datatypes[i][0].equals("image");
if( bImage )
valueToAssign = "";
else
valueToAssign = " = " + datatypes[i][1];
String sql = "create procedure #jtds_outputTest "
+ "@a1 " + datatypes[i][0] + " = null out "
+ "as select @a1" + valueToAssign;
stmt.executeUpdate(sql);
for( int pass=0; (pass<2 && !bImage) || pass<1; pass++ )
{
CallableStatement cstmt = con.prepareCall("{call #jtds_outputTest(?)}");
int jtype = getType(datatypes[i][2]);
if (pass == 1)
cstmt.setObject(1,null,jtype,10);
if (jtype == java.sql.Types.NUMERIC || jtype == java.sql.Types.DECIMAL)
{
cstmt.registerOutParameter(1, jtype, 10);
if (pass == 0)
cstmt.setObject(1,datatypes[i][2],jtype,10);
}
else if (jtype == java.sql.Types.VARCHAR)
{
cstmt.registerOutParameter(1, jtype, 255);
if (pass == 0)
cstmt.setObject(1,datatypes[i][2]);
}
else
{
cstmt.registerOutParameter(1, jtype);
if (pass == 0)
cstmt.setObject(1,datatypes[i][2]);
}
if( !bImage )
assertTrue(!cstmt.execute());
while(cstmt.getUpdateCount() != -1 && cstmt.getMoreResults());
if (jtype == java.sql.Types.VARBINARY)
{
assertTrue(compareBytes(cstmt.getBytes(1), (byte[])datatypes[i][2]) == 0);
}
else
if (datatypes[i][2] instanceof Number) {
Number n = (Number)cstmt.getObject(1);
assertEquals("Failed on " + datatypes[i][0], ((Number)cstmt.getObject(1)).doubleValue(), ((Number)datatypes[i][2]).doubleValue(),0.001);
}
else
{
assertEquals("Failed on " + datatypes[i][0], cstmt.getObject(1), datatypes[i][2]);
}
} // for (pass
stmt.executeUpdate(" drop procedure #jtds_outputTest");
} // for (int
}
public void testDatatypes0017() throws Exception
{
Connection cx = getConnection();
Statement stmt = cx.createStatement();
dropTable("#t0017");
/*
remove ( ), convert , to _
myXXXX, mynullXXXX
// Insert a row without nulls via a Statement
// Insert a row with nulls via a Statement
// Insert a row without nulls via a PreparedStatement
// Insert a row with nulls via a PreparedStatement
// Now verify that the database has the same data as we put in.
*/
}
public void testStatements0020() throws Exception
{
Connection cx = getConnection();
dropTable("#t0020a");
dropTable("#t0020b");
dropTable("#t0020c");
Statement stmt = cx.createStatement();
stmt.executeUpdate("create table #t0020a ( " +
" i1 int not null, " +
" s1 char(10) not null " +
") " +
"");
stmt.executeUpdate("create table #t0020b ( " +
" i2a int not null, " +
" i2b int not null, " +
" s2 char(10) not null " +
") " +
"");
stmt.executeUpdate("create table #t0020c ( " +
" i3 int not null, " +
" s3 char(10) not null " +
") " +
"");
int nextB = 1;
int nextC = 1;
for (int i = 1; i < 50; i++)
{
stmt.executeUpdate("insert into #t0020a " +
" values(" + i + ", " +
" 'row" + i + "') " +
"");
for (int j = nextB; (nextB % 5) != 0; j++, nextB++)
{
stmt.executeUpdate("insert into #t0020b " +
" values(" + i + ", " +
" " + j + ", " +
" 'row" + i + "." + j + "' " +
" )" +
"");
for (int k = nextC; (nextC % 3) != 0; k++, nextC++)
{
stmt.executeUpdate("insert into #t0020c " +
" values(" + j + ", " +
" 'row" + i + "." + j + "." + k + "' " +
" )" +
"");
}
}
}
Statement stmtA = cx.createStatement();
PreparedStatement stmtB = cx.prepareStatement(
"select i2b, s2 from #t0020b where i2a=?");
PreparedStatement stmtC = cx.prepareStatement(
"select s3 from #t0020c where i3=?");
ResultSet rs1 = stmtA.executeQuery("select i1 from #t0020a");
assertNotNull(rs1);
while (rs1.next())
{
int i1 = rs1.getInt("i1");
stmtB.setInt(1, rs1.getInt("i1"));
ResultSet rs2 = stmtB.executeQuery();
assertNotNull(rs2);
while (rs2.next())
{
stmtC.setInt(1, rs2.getInt(1));
ResultSet rs3 = stmtC.executeQuery();
assertNotNull(rs3);
if (rs3.next())
{
// nop
}
}
}
}
public void testBlob0021() throws Exception
{
byte smallarray[] =
{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
};
byte array1[] =
{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
};
String bigtext1 =
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"abcdefghijklmnop" +
"";
Connection cx = getConnection();
Statement stmt = cx.createStatement();
dropTable("#t0021");
stmt.executeUpdate(
"create table #t0021 ( " +
" mybinary binary(16) not null, " +
" myimage image not null, " +
" mynullimage image null, " +
" mytext text not null, " +
" mynulltext text null) ");
// Insert a row without nulls via a Statement
PreparedStatement insert = cx.prepareStatement(
"insert into #t0021( " +
" mybinary, " +
" myimage, " +
" mynullimage, " +
" mytext, " +
" mynulltext " +
") " +
"values(?, ?, ?, ?, ?) ");
insert.setBytes(1, smallarray);
insert.setBytes(2, array1);
insert.setBytes(3, array1);
insert.setString(4, "abcd" /* bigtext1 */);
insert.setString(5, "defg" /* bigtext1 */);
int count = insert.executeUpdate();
assertTrue(count == 1);
insert.close();
ResultSet rs = stmt.executeQuery("select * from #t0021");
assertNotNull(rs);
assertTrue("Expected a result set", rs.next());
byte[] a1 = rs.getBytes("myimage");
byte[] a2 = rs.getBytes("mynullimage");
assertTrue(compareBytes(a1, array1) == 0);
assertTrue(compareBytes(a2, array1) == 0);
cx.close();
}
public void testNestedStatements0022() throws Exception
{
Connection cx = getConnection();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -