SqlExecute.java
资源名称:wapjsp.rar [点击查看]
上传用户:xiao85513
上传日期:2010-01-11
资源大小:2160k
文件大小:1k
源码类别:
手机WAP编程
开发平台:
Java
- package tagclass;
- import javax.servlet.jsp.*;
- import javax.servlet.jsp.tagext.*;
- import java.sql.*;
- public class SqlExecute extends TagSupport
- {
- private String sql="";
- // private String flag="query";
- // private ResultSet rs;
- public String getSql()
- {
- return this.sql;
- }
- public void setSql(String newSql)
- {
- this.sql=newSql;
- }
- /*public String getFlag()
- {
- return this.flag;
- }
- public void setFlag(String newFlag)
- {
- this.flag=newFlag;
- }
- public ResultSet getRs()
- {
- return this.rs;
- }
- */
- public int doStartTag() throws JspException
- {
- if(this.getSql()=="")return SKIP_BODY;
- try
- {
- //jsp:连接mysql数据库
- Class.forName("org.gjt.mm.mysql.Driver").newInstance();
- String url ="jdbc:mysql://localhost/picring?user=nangua&password=2003herald&useUnicode=true&characterEncoding=8859_1";
- Connection con= DriverManager.getConnection(url);
- Statement statement=con.createStatement();
- /* if(this.flag=="update")
- statement.executeUpdate(this.getSql());
- else
- {
- rs = statement.executeQuery(this.sql);
- }
- */
- statement.executeUpdate(this.getSql());
- con.close();
- }
- catch(Exception e)
- {
- throw new JspException(e);
- }
- return SKIP_BODY;
- }
- }