Mysql表的类型

分为一种是MyISAM,另一种是InnoDB 
MYSQL默认的就是InnoDB 

创建表的时候显示指定

create table a(id int not null auto_increment primary key,name varchar(255)) ENGINE=InnoDB;    
或  
create table b(id int not null auto_increment primary key,name varchar(255)) ENGINE=MyISAM; 

SHOW TABLE STATUS;命令可以看到表的类型

使用ALTER命令可以对单个表的类型进行修改

ALTER TABLE talbe_name ENGINE=InnoDB/MyISAM; 

可以看到MySQL当前默认的新生成表的类型。

SHOW GLOBAL VARIABLES LIKE '%engine%'; 

JDBC有这个API,Statement.getGeneratedKeys(); 

Class.forName("com.mysql.jdbc.Driver");  
        Connection connection = DriverManager.getConnection ("jdbc:mysql://localhost:3306/testid","root","root");      
        // 创建带问号的参数化语句      
        String template = "insert into t_test(name) values(?) ";      
        PreparedStatement statement = connection.prepareStatement (template);      
        statement.setString(1, "langhua1");  
        statement.execute();   
        ResultSet rs = statement.getGeneratedKeys();  
        while(rs.next()){  
//获得主键  
            System.out.println(rs.getInt(1));  
        }  
        statement.close();  
        rs.close();  
        connection.close();  
  
connection.setAutoCommit(false);  
Statement stat = connection.getStatement();  
stat.executeUpdate("insert into test (name,password) values('123','321')");  
ResultSet rs = stat.executeQuery("select id from test where name='123'");  
rs.next();  
System.out.println(rs.getInt('id'));  
connection.commit();



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值