网络留言
导入数据库
mysql -p root -u
密码
show databases;
use demo;
source 路径
src建包org.easybooks.test.jdbc
SqlSrvDBConn
package org.easybooks.test.jdbc;
import java.sql.*;
public class SqlSrvDBConn {
private Statement stmt;
private Connection conn;
ResultSet rs;
//在构造方法中创建数据库连接
public SqlSrvDBConn(){
stmt=null;
try{
Class.forName("com.mysql.cj.jdbc.Driver");
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","123456");
}catch(Exception e){
e.printStackTrace();
}
rs=null;
}
//获取数据连接
public Connection getConn(){
return this.conn;
}
//执行查询类的SQL语句,有返回集
public ResultSet executeQuery(String sql)
{
try
{
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery(sql);
}catch(SQLException e){
System.err.println("Data.executeQuery: " + e.getMessage());
}
return rs;
}
//关闭对象
public void closeStmt()
{
try
{
stmt.close();
}catch(SQLException e){
System.err.println("Data.executeQuery: " + e.getMessage());
}
}
public void closeConn()
{
try
{
conn.close();
}catch(SQLException e){
System.err.println("Data.executeQuery: " + e.getMessage());
}
}
}
org.easybooks.test.model.vo
LyTable
package org.easybooks.test.model.vo;
import java.sql.Date;
public class LyTable implements java.io.Serializable{
//Fields
private Integer id;
private Integer userId;
private Date date;
private String title;
private String content;
//Property accessors
//属性 id 的 get/set 方法
public Integer getId(){
return this.id;
}
public void setId(Integer id){
this.id=id;
}
//属性 userId 的 get/set 方法
public Integer getUserId(){
return this.userId;
}
public void setUserId(Integer userId){
this.userId=userId;
}
//属性 date 的 get/set 方法
public Date getDate(){
return this.date;
}
public void setDate(Date date){
this.date=date;
}
//属性 title 的 get/set 方法
public String getTitle(){
return this.title;
}
public void setTitle(String title){
this.title=title;
}
//属性 content 的 get/set 方法
public String getContent(){
return this.content;
}
public void setContent(String content){
this.content=content;
}
@Override
public String toString() {
return "LyTable [id=" + id + ", userId=" + userId + ", date=" + date + ", title=" + title + ", content="
+ content + "]";
}
}
UserTable
package org.easybooks.test.model.vo;
public class UserTable {
//Fields
private Integer id;
private String username;
private String password;
//Property accessors
//属性 id 的 get/set 方法
public Integer getId(){
return this