我用的是oracle,有一个简单的sql语句:
select * from a where id=&p_id
现在在java中调用该sql,有方法能将参数&p_id的值传过去吗?

解决方案 »

  1.   

    用这个PreparedStatement 如何传?
      

  2.   

    pst.setString(1,''),看楼主的意思,=&p_id该是string吧,呵呵。其实还有很多方法啊,比如
    public <type> init(String p_id)
    {
      String strsel = "select * from a where id ="'"+p_id+"'";
      ...
    }
      

  3.   

    &p_id是sql的一个变量,不是string,这个sql是能直接在sql plus中运行的,
    运行时会弹出一个窗口要你输入&p_id的值.那么在java中如何执行该sql,不能对
    这个sql做任何修改?
      

  4.   

    String sql = "insert into a2(id,picture)values(?,?)";
    PreparedStatement pst = connection.prepareStatement(cmd);
    pst.setString(1,"12345"); 
                       ...
      

  5.   

    我再说一遍,我的sql一个字符都不能改,即:
    String sql = "select * from a where id=&p_id";
    然后如何让他执行?
      

  6.   

    看你的语句怎么像存储过程要把字符串里的@p_id当变量名,然后替换真正的变量值来执行?
      

  7.   


    String sql = "select * from a where id=?";
    public aa(String id){
     pStatement.setString(1, id); 
    .......}
      

  8.   

    楼主想达到什么样的目的?
    如果想和sql plus 一样,那你还是自己写吧.在传入这个值之前先解析这个串,跳出个对话框要求输入该值.