⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 questionadd.java

📁 它是利用jsp+javabean来编写的
💻 JAVA
字号:
/*
 * QuestionAdd.java
 *
 * Created on 2006年8月31日, 上午11:30
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ACTION;
import java.sql.*;
import PUBLIC.TestSql;
/**
 *
 * @author fish
 */
public class QuestionAdd extends TestSql{
    String UserName=null;
    String UserPassword=null;
    String QuestionContext=null;
    String Result="您尚未登录或登录超时<br><a href='index.jsp'>重新登录</a>";
    /** Creates a new instance of QuestionAdd */
    public QuestionAdd() {
    }
    public void setUserName(String s){  //获得管理员用户名
        UserName=s.trim(); 
    }
    public void setUserPassword(String s){  //获得管理员密码
        UserPassword=s.trim(); 
    }
    public void setQuestionContext(String c){ //获得题目的内容
        QuestionContext=FormatStr(c); //调用FormatStr对字符串进行转换
    }
    public String getResult(){
        ResultSet rs = null;
        String condition;
        try {
            condition="SELECT * FROM TestUser WHERE UserName="+"'"+UserName+"'"; //查找表[TestQuestion]中的指定题目
            rs=sql.executeQuery(condition);
            while(rs.next())
                if(UserName.equals("admin")&&UserPassword.equals(rs.getString("UserPassword").trim()))    //判断管理员密码是否与数据库一致
                {
                    StringBuffer buffer=new StringBuffer();
                    try {   //添加题目操作开始
                        condition="INSERT INTO TestQuestion(QuestionContents,QuestionTime) VALUES('"+QuestionContext+"',NOW())";    //新建题目的SQL语句
                        sql.executeUpdate(condition);
                        buffer.append("题目添加成功!");
                    } catch (SQLException ex) {
                        buffer.append("题目添加失败");
                        ex.printStackTrace();
                    }
                    Result=new String(buffer);  
                }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return Result;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -