2 glb920417 glb920417 于 2013.10.21 11:03 提问

新手入门 请大神告知怎么在网页上设置 能进入后台数据库查询资料

以下是公司前辈让我参考已有文档自己做的程序 也不知道对不对
package com.zjxcsoft.ge.user.action;

import java.sql.*;

import com.opensymphony.xwork.ActionSupport;
import java.sql.Connection;

public class UserAction extends ActionSupport {

public UserAction() {

}
public void query(Connection conn, String sql){
    try{
    if(conn==null){
    throw new Exception("database connection can't use!");
    }
    if(sql==null) throw new Exception("check your parameter: 'sql'! don't input null!");
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(sql);
    ResultSetMetaData rmeta = rs.getMetaData();
    int numColumns = rmeta.getColumnCount();
    while(rs.next())
       {
         for(int i = 0;i< numColumns;i++)
         {
        String sTemp = rs.getString(i+1);
        System.out.print(sTemp+"  ");
         }
        System.out.println("");
       }
    }catch(Exception e){
    System.out.println("query error:"+e);
    }
    }   
public String getUserList(String sql1) {

    com.zjxcsoft.util.DBControl dbc = new com.zjxcsoft.util.DBControl();
    com.zjhcsoft.util.DbAction dba = new com.zjhcsoft.util.DbAction();
    Connection conn = null;
    conn = dbc.getDBConnetion();
    try{
        String sql = sql1;
        query(conn,sql);
        conn.close();
        }catch(SQLException se){
        System.out.println(se);
        } catch(Exception e){
        System.out.println(e);
        }
        return "success";
}

// public static void main(String[] args) {
// UserAction user = new UserAction();
// String sql = "select * from GEUSER";
// user.getUserList(sql);
// }

package com.zjxcsoft.ge.user.service;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zjxcsoft.ge.user.action.UserAction;
import com.zjxcsoft.ge.user.domain.UserDomain;
import com.zjxcsoft.system.persistent.db.ibatis.IbatisDao;

public class UserService {
private Connection conn = null;
private IbatisDao dao = null;

  public UserService() {
  }

  public UserService(Connection con) {
    this.conn = con;
  }

 public List UserList(String sqll){

            if(conn==null){
                System.out.println("database connection can't use!");
            }


      PreparedStatement pstmt = null;
      ResultSet rs = null;
      ArrayList list=new ArrayList();

      try {
        String sql=sqll;
        pstmt=this.conn.prepareStatement(sql);
        rs=pstmt.executeQuery();
        while(rs.next()){
            UserDomain domain=new UserDomain();
            domain.setUserid(rs.getString("userid"));
            domain.setCustomid(rs.getString("customid"));
            domain.setUsername(rs.getString("username"));
            System.out.println(rs.getString("userid")+" "+rs.getString("customid")+" "+rs.getString("username"));
            list.add(domain);
        }
          rs.close();
          rs = null;
          pstmt.close();
          pstmt = null;     
    } catch (SQLException e) {
        e.printStackTrace();
    }finally{
          try {
              if (rs != null) {
                rs.close();
                rs = null;
              }
              if (pstmt != null) {
                pstmt.close();
                pstmt = null;
              }
            }
            catch (Exception e) {
              e.printStackTrace();
            }
    }
    return list;
  } 
 public static void main(String[] args) {

     UserAction user = new UserAction();
        String sql = "select userid,customid,username from geuser";
        user.getUserList(sql);
    }

public Connection getConn() {
    return conn;
}

public void setConn(Connection conn) {
    this.conn = conn;
}

public IbatisDao getDao() {
    return dao;
}

public void setDao(IbatisDao dao) {
    this.dao = dao;
}

}

最后是自己做的一个简单的网页 我知道有问题 但是不知道具体在哪 怎么修改 请大神帮帮忙
因为基础比较差 所以写的很凌乱 有些地方可能与主题无关也不知道
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/webwork" prefix="ww" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



搜索



<script src="./js/cookie.js" type="text/javascript"></script>

function check(){ var userid = document.getElementById("userid"); if(userid.value==null||userid.value==""){ alert(" 用户编号不能为空,请填写!"); domainid.focus(); return false; } function submit(){ var pro = document.forms[0]; pro.action = "user!getUserList.action"; pro.submit(); } }


SELECT FROM GEUSER





');">

/ww:if

');"> var tempareaid='<ww:property value="userid"/>';

/ww:iterator

/ww:if
<!--modify 3-->

document.getElementById("userid").value='<ww:property value="userid"/>';

/ww:if


Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!