1 如果是导出数据库,可以用java调用数据库的备份SQl语句 2 如果仅仅导出数据,请参考如下样例,其中tablename是表格的名字,pk指是否包含主键注意:对于二进制和包含特殊字符的字段数据,需要额外处理,目前这个只能用于最简单的。另:可参考 phpMyAdmin的导出功能本代码采用SQL Server 2000 数据库[code = Java] <% @ page language = " java " contentType = " text/html; charset=GBK " pageEncoding = " GBK " %> <% @ page import = " java.sql.* " %> <% boolean showPK = ParamUtils.getIntParameter(request, " pk " , 0 ) == 1 ; String tableName = request.getParameter( " tablename " ); if (tableName == null || tableName.trim().length() == 0 ) ... { out.println("表格名称为空!"); return; } Connection con = null ; Statement stat = null ; ResultSet rs = null ; try ... { con = Factory.getDataSource().getConnection(); if (con == null) ...{ out.println("得到数据库连接失败!"); return; } stat = con.createStatement(); rs = stat.executeQuery("select * from " + tableName + " " + NoNull.toString(request.getParameter("sql"))); if(showPK)...{ out.print("SET IDENTITY_INSERT dbo."+tableName+" ON<br>"); } ResultSetMetaData md = rs.getMetaData(); String[] fieldNames = new String[md.getColumnCount()]; StringBuilder builder = new StringBuilder("insert into " + tableName + "("); for (int i = 0; i < md.getColumnCount(); i++) ...{ fieldNames[i] = md.getColumnName(i + 1); if (!showPK && fieldNames[i].equalsIgnoreCase("ID")) ...{ continue; } builder.append(fieldNames[i] + ","); } // 去掉最后一个逗号 builder.deleteCharAt(builder.length() - 1); builder.append(") values("); StringBuilder line = new StringBuilder(); String value; while (rs.next()) ...{ line.delete(0, line.length()); line.append(builder.toString()); for (int i = 0; i < fieldNames.length; i++) ...{ if (!showPK && fieldNames[i].equalsIgnoreCase("ID")) ...{ continue; } value = rs.getString(fieldNames[i]); if (value == null) ...{ line.append("null,"); } else ...{ line.append("'"); line.append(value); line.append("',"); } } line.deleteCharAt(line.length() - 1); line.append(");"); out.println(line.toString() + "<br/>"); } if(showPK)...{ out.print("SET IDENTITY_INSERT dbo."+tableName+" OFF<br>"); } } catch (Exception ex) ... { out.print(ex); } finally ... { if (stat != null) ...{ try ...{ stat.close(); } catch (Exception ex) ...{ } } if (con != null) ...{ try ...{ con.close(); } catch (Exception ex) ...{ } } } %> [ / code]