package ch08;
import java.sql.*;
public class JavaBeanProject {
private String drivername="com.mysql.jdbc.Driver";
private String url="jdbc:mysql://localhost:3306/adminlogin?useUnicode=true&characterEncoding=gbk";
private String user="root";
private String password="123456";
private String s[];
public String getDrivername() {
return drivername;
}
public void setDrivername(String drivername) {
this.drivername = drivername;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String[] getS() {
return s;
}
public void setS(String[] s) {
this.s = s;
}
public Connection getConnection()
{
try
{
Class.forName(drivername);
return DriverManager.getConnection(url, user, password);
}catch(Exception e)
{
e.printStackTrace();
return null;
}
}
public ResultSet select(String sqls)//查询
{
PreparedStatement stmt;
try
{
stmt=getConnection().prepareStatement(sqls);
for(int i=0;i<s.length;i++)
stmt.setString(i+1,s[i]);
return stmt.executeQuery();
}catch(Exception e){
e.printStackTrace();
return null;
}
}
public void insertJournal(String sqls){//添加新闻
PreparedStatement stmt;
//int rs=0;
try {
stmt = getConnection().prepareStatement(sqls);
for(int i=0;i<s.length;i++)
stmt.setString(i+1,s[i]);
stmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
} /*finally{
return rs;
}*/
}
public void updateJournal(String sqls){//修改新闻
PreparedStatement stmt;
try {
stmt = getConnection().prepareStatement(sqls);
for(int i=0;i<s.length;i++)
stmt.setString(i+1,s[i]);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
public void deleteJournal(String sqls){//删除新闻
PreparedStatement stmt;
try {
stmt = getConnection().prepareStatement(sqls);
for(int i=0;i<s.length;i++)
stmt.setString(i+1,s[i]);
stmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
}
}