package coreservlets;
import java.sql.*;
import java.util.*;
public class BBSQuery{
public void BBSInsert(RegInfo regInfo){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
PreparedStatement ptstmt=con.prepareStatement("insert into userInfo values(?,?,?,?,?,?,?)");
ptstmt.setString(1,regInfo.getUsername());
ptstmt.setString(2,regInfo.getPassword());
ptstmt.setString(3,regInfo.getSex());
ptstmt.setString(4,regInfo.getYear());
ptstmt.setString(5,regInfo.getMonth());
ptstmt.setString(6,regInfo.getDate());
ptstmt.setString(7,regInfo.getNote());
ptstmt.executeUpdate();
con.close();
ptstmt.close();
}
catch(SQLException ex){
}
}
public void ATC_Insert(client atcInfo){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
PreparedStatement ptstmt=con.prepareStatement("insert into client values(?,?,?,?)");
ptstmt.setString(1,atcInfo.getName());
ptstmt.setString(2,atcInfo.getTitle());
ptstmt.setString(3,atcInfo.getContent());
ptstmt.setString(4,atcInfo.getTime());
ptstmt.executeUpdate();
con.close();
ptstmt.close();
}
catch(SQLException ex){
}
}
public void Reviewer_Insert(reviewer r){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
PreparedStatement ptstmt=con.prepareStatement("insert into review values(?,?,?,?)");
ptstmt.setString(1,r.getId());
ptstmt.setString(2,r.getName());
ptstmt.setString(3,r.getComment());
ptstmt.setString(4,r.getTime());
ptstmt.executeUpdate();
con.close();
ptstmt.close();
}
catch(SQLException ex){
}
}
public ArrayList Post_Select(){
ArrayList mystr=new ArrayList();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
String SQL="select * from client";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(SQL);
ArrayList mystr1=new ArrayList();
client c=null;
while(rs.next()){
String name=rs.getString("name");
String title=rs.getString("title");
String content=rs.getString("content");
String time=rs.getString("time");
c=new client(name,title,content,time);
Object object=(Object)c;
mystr1.add(object);
}
mystr=mystr1;
con.close();
stmt.close();
}
catch(SQLException ex){
}
return mystr;
}
public boolean User_Select(String name,String password){
boolean flag=false;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
String SQL="select * from userInfo where username=? and password=?";
PreparedStatement ptstmt=con.prepareStatement(SQL);
ptstmt.setString(1,name);
ptstmt.setString(2,password);
ResultSet rs=ptstmt.executeQuery();
while(rs.next()){
String sex=rs.getString("sex");
if(sex!=null){
flag=true;
}
}
con.close();
ptstmt.close();
}
catch(SQLException ex){
}
return flag;
}
public ArrayList Post_Select1(String title){
ArrayList mystr=new ArrayList();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
String SQL="select * from client where title=?";
PreparedStatement ptstmt=con.prepareStatement(SQL);
ptstmt.setString(1,title);
ResultSet rs=ptstmt.executeQuery();
ArrayList mystr1=new ArrayList();
client c=null;
while(rs.next()){
String name=rs.getString("name");
String content=rs.getString("content");
String time=rs.getString("time");
c=new client(name,title,content,time);
Object object=(Object)c;
mystr1.add(object);
}
mystr=mystr1;
con.close();
ptstmt.close();
}
catch(SQLException ex){
}
return mystr;
}
public ArrayList Review_Select(String id){
ArrayList mystr=new ArrayList();
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ex){
System.exit(-1);
}
try{
String URL="jdbc:odbc:BBS";
Connection con=DriverManager.getConnection(URL);
String SQL="select * from review where ID=?";
PreparedStatement ptstmt=con.prepareStatement(SQL);
ptstmt.setString(1,id);
ResultSet rs=ptstmt.executeQuery();
ArrayList mystr1=new ArrayList();
reviewer r=null;
while(rs.next()){
String name=rs.getString("name");
String comment=rs.getString("comment");
String time=rs.getString("time");
r=new reviewer(id,name,comment,time);
Object object=(Object)r;
mystr1.add(object);
}
mystr=mystr1;
con.close();
ptstmt.close();
}
catch(SQLException ex){
}
return mystr;
}
public static void main(String[] args){
try{
BBSQuery bbs=new BBSQuery();
boolean a=bbs.User_Select("22","22");
System.out.println(a);
}
catch(Exception x){}
}
}