//JDBC_BBS.java
import java.sql.*;
public class JDBC_BBS {
public static void main(String[] args) {
try {
Class.forName("com.mysql.jdbc.Driver");// 注册MySQL 的驱动
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// 先定义变量,后使用和关闭
Connection conn = null;// 数据库连接
Statement stmt = null;// 数据库表达式
ResultSet rs = null;// 结果集
try {
// 获取数据库的连接
conn = java.sql.DriverManager
.getConnection(
"jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK",
"root", "root");
// root是用户名,密码为root,编码为GBK
// 获取表达式
stmt = conn.createStatement();
stmt.executeUpdate("drop table student");// 删除表student
stmt.executeUpdate("drop table discuss");// 删除表discuss
stmt.executeUpdate("drop table reply");// 删除表reply
// 创建表student
stmt
.executeUpdate("create table student(id int not null auto_increment,"
+ "username varchar(20) unique,"
+ "password varchar(20) not null,"
+ "sex varchar(8) not null,"
+ "age varchar(4) ,"
+ "birth varchar(20) not null,"
+ "telephone varchar(12),"
+ "email varchar(40) not null,"
+ "primary key (id))");
// 创建表discuss
stmt.executeUpdate("create table discuss(name char(20) not null,"
+ "email char(40) not null," + "subject char(60) not null,"
+ "content text not null," + "time char(40),"
+ "username char(20),"
+ "id int not null auto_increment,primary key (id))");
// 创建表reply
stmt.executeUpdate("create table reply(name char(20) not null,"
+ "content text not null," + "time char(40),reply int,"
+ "id int not null auto_increment," + "primary key (id))");
stmt
.executeUpdate("insert into discuss(name,email,subject,content,time,username) values('FrogKing', 'menghuan277717@163.com','Test','The first input data!','2009年4月18日18:30:30','FrogKing')");
// 执行插入数据的 SQL
stmt
.executeUpdate("insert into Student(username,password,sex,age,birth,telephone,email) values('Tome', '1234','男',20,'','13820991219','menghuan277717@163.com')");
stmt
.executeUpdate("insert into Student(username,password,sex,age,birth,telephone,email) values('Bell', '1234','男',20,'','13820991219','menghuan277717@163.com')");
stmt
.executeUpdate("insert into Student(username,password,sex,age,birth,telephone,email) values('Jack', '1234','男',20,'','13820991219','menghuan277717@163.com')");
stmt
.executeUpdate("insert into Student(username,password,sex,age,birth,telephone,email) values('FrogKing', '123456','男',20,'','13820991219','menghuan277717@163.com')");
} catch (SQLException e) {
e.printStackTrace();
} finally {// 释放资源
// try {
// rs.close();
// } catch (SQLException e) {
// }
try {
stmt.close();
} catch (SQLException e) {
}
try {
conn.close();
} catch (SQLException e) {
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java Web.rar (36个子文件)
Java Web
附件程序
test
reply.frm 8KB
student.frm 9KB
discuss.frm 9KB
BBSTalk
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.jsdt.ui.superType.container 49B
.jsdtscope 406B
src
JDBC_BBS.java 3KB
.project 1KB
WebRoot
person.jsp 1KB
detail.jsp 5KB
discuss.jsp 4KB
META-INF
MANIFEST.MF 39B
opendata.jsp 1KB
saveNewTitle.jsp 2KB
WEB-INF
web.xml 392B
classes
JDBC_BBS.class 3KB
lib
mysql-connector-java-5.0.3-bin.jar 482KB
getPassword.jsp 3KB
login.html 2KB
newTitle.jsp 2KB
Pictures
discuss.jpg 22KB
MainJPG.jpg 40KB
111.jpg 56KB
head.bmp 73KB
001.jpg 36KB
BGBlue.jpg 2KB
delete.bmp 5KB
saveregister.jsp 2KB
enter.jsp 2KB
delete.jsp 2KB
convert.jsp 1009B
register.jsp 7KB
saveRevert.jsp 2KB
MainForm.jsp 970B
.mymetadata 300B
.classpath 533B
.myeclipse
共 36 条
- 1
XIA09124140218
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页