JAVA全系列 教程
3762个小节阅读:7093.1k
目录
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
创建表
xxxxxxxxxx
CREATE TABLE `users` (
`userid` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(30) DEFAULT NULL,
`userage` int(11) DEFAULT NULL,
PRIMARY KEY (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
添加数据
xxxxxxxxxx
/**
* Statement对象的使用
*/
public class StatementTest {
/**
* 添加用户
*/
public void insertUsers(String username,int userage){
Connection connection = null;
Statement statement = null;
try{
//获取Connection对象。
connection = JdbcUtils.getConnection();
//获取Statement对象
statement = connection.createStatement();
//定义需要执行的SQL语句
String sql = "insert into users values(default,'"+username+"',"+userage+")";
//执行SQL,返回boolean值,如果sql有结果集返回,那么返回值为true,如果没有结果集返回,则返回false。
boolean execute = statement.execute(sql);
System.out.println(execute);
}catch(Exception e){
e.printStackTrace();
}finally{
JdbcUtils.closeResource(statement,connection);
}
}
}