留言板的问题

      这一周我们小组成员经过商议,决定先搭建一个框架,建,立以每个人的名字命名的包,每个人在相应的包下写自己的代码。上一周我主要写了留言板的jsp页面。后来感觉不好,又重新写了一个。在jsp页面的基础上有加上了数据库的链接。大部分时间是在自己电脑上做的,留言板部分全部结束。但是运行的时候牵扯到数据库的问题就不能运行,这个问题没找到原因。星期五的时候将工程拷到机房的电脑,不知道什么问题,将工程导入电脑后,myeclipse出现好多问题,jap页面打不开。后来在刘老师的帮助下,这问题解决了,后来发布工程的时候,tomcat6.0不管用。问题继续解决中。

     首先建了一个DB类,代码如下:package org.suncongcong.dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
import org.model.Student;
import org.model.Lyxx;
import org.model.Lyhf;


public class DB {
 Connection ct;
 PreparedStatement pstmt;
 public DB(){
  try {
   
   Class.forName("com.mysql.jdbc.Driver");
    ct=DriverManager.getConnection
    ("jdbc:sqlserver://localhost:3306;databaseName=jxpt","root","root");
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
public Student checkStudent(String StuName,String Stupwd){
 try{
  pstmt=ct.prepareStatement("select * from student where StuName=? and Stupwd=?");
  pstmt.setString(1, StuName);
  pstmt.setString(2, Stupwd);
  ResultSet rs=pstmt.executeQuery();
  Student student=new Student();
  while(rs.next()){
   student.setStuId(rs.getInt(1));
   student.setStuName(rs.getString(2));
   student.setStupwd(rs.getInt(3));
   return student;

 }
  return null;
}catch(Exception e){
 e.printStackTrace();
 return null;

     }
  }
public String  getStuName(int StuId){
 try{
 pstmt=ct.prepareStatement("select * from student where StuId=?");
  pstmt.setInt(1, StuId);
  ResultSet rs=pstmt.executeQuery();
  while(rs.next()){
   return rs.getString("StuName");
  }
  return null;
 }catch(Exception e){
  e.printStackTrace();
  return null;
 }
}
public ArrayList findLyInfo(){
 try{
  ArrayList al=new ArrayList();
  pstmt=ct.prepareStatement("select * from lyTable");
  ResultSet rs=pstmt.executeQuery();
  while(rs.next()){
   Lyxx ly=new Lyxx();
   ly.setStuId(rs.getInt(1));
   ly.setLyTime(rs.getDate(2));
   ly.setLyTheme(rs.getString(4));
   ly.setLycontent(rs.getString(5));
   al.add(ly);
  }
  return al;
 }catch(Exception e){
  e.printStackTrace();
  return null;
 }
}
public boolean addInfo(Lyxx ly){
 try {
  pstmt=ct.prepareStatement("insert into Lyxx(lyID,lycontent,lyTheme,lyTime,StuID) values(?,?,?,?,?)");
  pstmt.setInt(1, ly.getStuId());
  pstmt.setDate(2, (java.sql.Date) ly.getLyTime());
  pstmt.setString(3, ly.getLyTheme());
  pstmt.setString(4, ly.getLycontent());
  pstmt.setInt(5, ly.getStuId());
  pstmt.executeUpdate();
  return true;
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return false;
 }
 
}
public boolean insertstudent(String StuName,String Stupwd){
 try {
  pstmt=ct.prepareStatement("insert into student(StuName,Stupwd) values(?,?)");
  pstmt.setString(1, StuName);
  pstmt.setString(2, Stupwd);
  pstmt.executeUpdate();
  return true;
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return false;
 }
}


}

然后又新建了3个类,分别命名为:AddServlet.java、MainServlet.java、RegisterServlet.java代码很长,就不写啦。

      又重新建了4个jsp页面,分别是登陆界面,注册界面,留言界面,留言成功界面。现在数据库连接有点问题,问题正在解决中。下周我们打算把所有代码完成。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值