package client.frw;
import java.sql.Connection;
import java.sql.Statement;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Test;
public class MysqlLockTest {
@Test
public void testAddPartition() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
String insert = "alter table kaps_zjyils add PARTITION (PARTITION p" + RandomStringUtils.randomNumeric(8) + " values less than('20150424'));";
System.out.println(insert);
st.execute(insert);
conn.rollback();//rollback不起作用
}
@Test
public void testCreateTest2() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
String insert = "insert into tb_test1 values('" + RandomStringUtils.randomNumeric(8) + "')";
System.out.println(insert);
st.execute(insert);
//ddl 自动提交
String ddl = "create table t" + RandomStringUtils.randomNumeric(8) + " (name1 varchar (30) null)";
st.execute(ddl);
System.out.println(ddl);
insert = "insert into tb_test1 values('" + RandomStringUtils.randomNumeric(8) + "')";
System.out.println(insert);
st.execute(insert);
conn.rollback();
}
@Test
public void testDropTest2() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
String ddl = "drop table tb_test1;";
System.out.println(ddl);
System.out.println(conn.createStatement().execute(ddl));
// conn.commit();
conn.rollback();
}
@Test
public void testCreateTest1() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
String ddl = "create table tb_test1 (name1 varchar (30) null);";
System.out.println(ddl);
System.out.println(conn.createStatement().execute(ddl));
// conn.commit();
conn.rollback();
}
}
查询分区的方法
SELECT
partition_name part,
partition_expression expr,
partition_description descr,
table_rows
FROM
INFORMATION_SCHEMA.partitions
WHERE
TABLE_SCHEMA = schema()
AND TABLE_NAME='table';
对ddl操作,不支持事物,自动commit
import java.sql.Connection;
import java.sql.Statement;
import org.apache.commons.lang.RandomStringUtils;
import org.junit.Test;
public class MysqlLockTest {
@Test
public void testAddPartition() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
String insert = "alter table kaps_zjyils add PARTITION (PARTITION p" + RandomStringUtils.randomNumeric(8) + " values less than('20150424'));";
System.out.println(insert);
st.execute(insert);
conn.rollback();//rollback不起作用
}
@Test
public void testCreateTest2() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
Statement st = conn.createStatement();
String insert = "insert into tb_test1 values('" + RandomStringUtils.randomNumeric(8) + "')";
System.out.println(insert);
st.execute(insert);
//ddl 自动提交
String ddl = "create table t" + RandomStringUtils.randomNumeric(8) + " (name1 varchar (30) null)";
st.execute(ddl);
System.out.println(ddl);
insert = "insert into tb_test1 values('" + RandomStringUtils.randomNumeric(8) + "')";
System.out.println(insert);
st.execute(insert);
conn.rollback();
}
@Test
public void testDropTest2() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
String ddl = "drop table tb_test1;";
System.out.println(ddl);
System.out.println(conn.createStatement().execute(ddl));
// conn.commit();
conn.rollback();
}
@Test
public void testCreateTest1() throws Exception {
Connection conn = MysqlConnectionTest.createConnection();
conn.setAutoCommit(false);
String ddl = "create table tb_test1 (name1 varchar (30) null);";
System.out.println(ddl);
System.out.println(conn.createStatement().execute(ddl));
// conn.commit();
conn.rollback();
}
}
查询分区的方法
SELECT
partition_name part,
partition_expression expr,
partition_description descr,
table_rows
FROM
INFORMATION_SCHEMA.partitions
WHERE
TABLE_SCHEMA = schema()
AND TABLE_NAME='table';
对ddl操作,不支持事物,自动commit