程序目的是 先从一个表格中取出 物品id 和物品名称mc,然根据具id从表0中取出物品属性,再根据物品id从表1中取出物品的配送信息,写入excel,然后根据id从表2中取出物品的 部门信息,写入同一个excel 。然后循环到第二个id
try
{
connectSQL con=new connectSQL();
ResultSet r=con.executeQuery("select id,mc from daima");
while (r.next())
{
**获取id和mc**
String sqlstr0="select name from table0 where id="+'id'+" ";
ResultSet r0= con.executeQuery(sqlstr0);
while (r0.next())
{
String sqlstr1="select * from table1 where id="+'id'+" ";
ResultSet rss= con.executeQuery(sqlstr1);
while (rss.next())
{
}
rss.close();
String sqlstr2="select * from table2 where id="+'id'+" ";
ResultSet rs= con.executeQuery(sqlstr2);
while (rs.next())
{ }
rs.close();
}r.close();
}catch(Exception e)
{
System.out.println(e);
}
}
try
{
connectSQL con=new connectSQL();
ResultSet r=con.executeQuery("select id,mc from daima");
while (r.next())
{
**获取id和mc**
String sqlstr0="select name from table0 where id="+'id'+" ";
ResultSet r0= con.executeQuery(sqlstr0);
while (r0.next())
{
String sqlstr1="select * from table1 where id="+'id'+" ";
ResultSet rss= con.executeQuery(sqlstr1);
while (rss.next())
{
}
rss.close();
String sqlstr2="select * from table2 where id="+'id'+" ";
ResultSet rs= con.executeQuery(sqlstr2);
while (rs.next())
{ }
rs.close();
}r.close();
}catch(Exception e)
{
System.out.println(e);
}
}
select * from a join b on a.id=b.id
join c on b.id=c.id
一样的啊!你表连接查询去除100多个id的所有信息,一次性的插入到EXCEL里。