values(?,  )
?   你要确定类型跟字段table1 的 a 字段 一致
select b,c from table2 where d=?   要确保返回一行其实可以这样写
insert into table1(a, b, c)
select ?, b, c from table2 where d=?;
? 并不一定要是 TABLE2的字段

解决方案 »

  1.   

    insert into table1(a,b,c) values(?,(select b,c from table2 where d=?))
    这是一种连接数据池的预编译方法
    在进行正式提交的时候你必须在?的位置插入对应的数据下面是一个例子:
    String sql = "insert into files(filesid,filestitle,author,content,fileid,collectdate)values(?,?,?,?,?,sysdate)"; 
    stmt = conn.prepareStatement(sql);
           stmt.setInt(1, filesID);
           stmt.setString(2, filestitle);
           stmt.setString(3, author);
           stmt.setString(4, content);
           stmt.setString(5,fileID);
    stmt.executeUpdate();