package com.erp.app.count;
import java.io.*;
import java.sql.*;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2009-2-9
* Time: 16:49:16
* To change this template use File | Settings | File Templates.
*/
public class xx {
String url = "jdbc:oracle:thin:@192.168.1.200:1521:picc";
String user = "piccsys";
String password = "piccsys";
public String Count(String Ptable, String Pid) throws Exception {
Connection conn = DriverManager.getConnection(url, user, password);
ResultSet rs = null;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select count(*) as rec from " + Ptable + " a ,T_BUS_MODEL b where a.SMODELCODE=b.SMODELCODE " +
"and a.SMODELCODE='" + Pid + "'";
rs = stmt.executeQuery(sql);
String returnStr = "";
if (rs.next())
returnStr = rs.getString("rec");
return returnStr;
}
public String scsqlx() throws Exception {
StringBuffer sqlx = new StringBuffer();
String url = "jdbc:oracle:thin:@192.168.1.200:1521:picc";
String user = "piccsys";
String password = "piccsys";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print(e);
}
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select a.SMODELCODE ,a.SMODELNAME , a.STABLE_NAME from T_BUS_MODEL a where rownum <= 100 ";
ResultSet rs = stmt.executeQuery(sql);
String[] row = new String[6];
sqlx.append(" <table>\n" +
" <thead>\n" +
" <tr>\n" +
" <td>车型编码</td>\n" +
" <td>车型名称</td>\n" +
" <td>零件总数量</td>\n" +
" <td>有效数量</td>\n" +
" </tr>\n" +
" </thead>");
for (int i = 0; rs.next(); i++) {
row[0] = rs.getString("SMODELCODE");
row[1] = rs.getString("SMODELNAME");
row[2] = rs.getString("STABLE_NAME");
row[3] = this.Count(row[2], row[0]);
sqlx.append("<tr>");
sqlx.append("<td>'" + row[0] + "'<td>");
sqlx.append("<td>'" + row[1] + "'<td>");
sqlx.append("<td>'" + row[3] + "'<td>");
sqlx.append("<td><td><tr>");
}
sqlx.append("</table>");
return sqlx.toString();
}
public void write(String path, String content) {
String s = new String();
String s1 = new String();
try {
File f = new File(path);
if (f.exists()) {
System.out.println("文件存在");
} else {
System.out.println("文件不存在,正在创建...");
if (f.createNewFile()) {
System.out.println("文件创建成功!");
} else {
System.out.println("文件创建失败!");
}
}
BufferedReader input = new BufferedReader(new FileReader(f));
while ((s = input.readLine()) != null) {
s1 += s + "\n";
}
System.out.println("文件内容:" + s1);
input.close();
s1 += content;
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
System.out.println("begin");
xx x = new xx();
x.write("D:\\123.html", x.scsqlx());
System.out.println("end");
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}
import java.io.*;
import java.sql.*;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2009-2-9
* Time: 16:49:16
* To change this template use File | Settings | File Templates.
*/
public class xx {
String url = "jdbc:oracle:thin:@192.168.1.200:1521:picc";
String user = "piccsys";
String password = "piccsys";
public String Count(String Ptable, String Pid) throws Exception {
Connection conn = DriverManager.getConnection(url, user, password);
ResultSet rs = null;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select count(*) as rec from " + Ptable + " a ,T_BUS_MODEL b where a.SMODELCODE=b.SMODELCODE " +
"and a.SMODELCODE='" + Pid + "'";
rs = stmt.executeQuery(sql);
String returnStr = "";
if (rs.next())
returnStr = rs.getString("rec");
return returnStr;
}
public String scsqlx() throws Exception {
StringBuffer sqlx = new StringBuffer();
String url = "jdbc:oracle:thin:@192.168.1.200:1521:picc";
String user = "piccsys";
String password = "piccsys";
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (java.lang.ClassNotFoundException e) {
System.err.print(e);
}
Connection conn = DriverManager.getConnection(url, user, password);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
String sql = "select a.SMODELCODE ,a.SMODELNAME , a.STABLE_NAME from T_BUS_MODEL a where rownum <= 100 ";
ResultSet rs = stmt.executeQuery(sql);
String[] row = new String[6];
sqlx.append(" <table>\n" +
" <thead>\n" +
" <tr>\n" +
" <td>车型编码</td>\n" +
" <td>车型名称</td>\n" +
" <td>零件总数量</td>\n" +
" <td>有效数量</td>\n" +
" </tr>\n" +
" </thead>");
for (int i = 0; rs.next(); i++) {
row[0] = rs.getString("SMODELCODE");
row[1] = rs.getString("SMODELNAME");
row[2] = rs.getString("STABLE_NAME");
row[3] = this.Count(row[2], row[0]);
sqlx.append("<tr>");
sqlx.append("<td>'" + row[0] + "'<td>");
sqlx.append("<td>'" + row[1] + "'<td>");
sqlx.append("<td>'" + row[3] + "'<td>");
sqlx.append("<td><td><tr>");
}
sqlx.append("</table>");
return sqlx.toString();
}
public void write(String path, String content) {
String s = new String();
String s1 = new String();
try {
File f = new File(path);
if (f.exists()) {
System.out.println("文件存在");
} else {
System.out.println("文件不存在,正在创建...");
if (f.createNewFile()) {
System.out.println("文件创建成功!");
} else {
System.out.println("文件创建失败!");
}
}
BufferedReader input = new BufferedReader(new FileReader(f));
while ((s = input.readLine()) != null) {
s1 += s + "\n";
}
System.out.println("文件内容:" + s1);
input.close();
s1 += content;
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
System.out.println("begin");
xx x = new xx();
x.write("D:\\123.html", x.scsqlx());
System.out.println("end");
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
}