救一条sql语句

zzm76 2003-08-21 11:26:17

String sql="insert table1 (id) values ('4')";
可能被插入的表是个变量,可能是table1也可能是table2或者table3

如果是查找的话可以用String sql="select * from "+tableName;处理
插入怎么搞好呢?



...全文
23 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ticlej 2003-08-21
  • 打赏
  • 举报
回复
如果字段都是一致的,那就用String sql="insert "+ tableName +" (id) values ('4')";
但如果不一定是"id",就看你的需求了.
topbit 2003-08-21
  • 打赏
  • 举报
回复
private static final String SQL_SELECT_TABLE1 = "select * from Table1";
private static final String SQL_SELECT_TABLE2 = "select * from Table2";
private static final String SQL_SELECT_TABLE3 = "select * from Table3";

public ResultSet query(int tableIndex)
{
switch(tableIndex)
{
case 1:
return getConnection().prepareStatement(SQL_SELECT_TABLE1).execute();
case 2:
return getConnection().prepareStatement(SQL_SELECT_TABLE2).execute();
case 3:
return getConnection().prepareStatement(SQL_SELECT_TABLE3).execute();
}
}
curry913 2003-08-21
  • 打赏
  • 举报
回复
???
String sql="insert "+ tableName +" (id) values ('4')";

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧