新手小弟用java程序调用数据库,添加,删除,修改等操作.
由于数据库关键字为整型.
我使用如下语句:
Statement stmt1=con.createStatement();

String del="delete from table1 where id = '"+1+"'";//id为整型
        stmt1.executeUpdate(del)一直不成功.
请问大虾们,应该怎么写这个按整型变量来删除数据库中的一条记录.

解决方案 »

  1.   

    结帖率:75.00%   多了一倍
    试试
    String del="delete from table1 where id = '"+1+"'";
    改成
    String del="delete from table1 where id = "+1;
      

  2.   

            希望能结贴。。
    String del="delete from table1 where id =1";
                       
      

  3.   

    Statement stmt1=con.createStatement(); 
    String del="delete from table1 where id = " + 1; 
    stmt1.executeUpdate(del);
      

  4.   


    public class UpdateDatas{   //前面这个连接数据库的方法就LZ自己去写了
       public Connection getConnection()throws Exception{  
        .......
       }
       public boolean delDatasLine(int id){ 
          boolean bl = false;
          Connection con  = null;
          Statement st = null;
           try{
             con = this.getConnection();
             st = con.createStatement();
           string sql =   
          //界面上让用户去选吧,选哪个就调用此方法删除哪个。
          "UPDATE ***(表名) SET id = '"+id+"'";
          if(st.exeUpdate(sql)!=0){ 
             bl = true;
          }
       }catch(Exception ex){
         ex.printStackTrace();
        }finally{
          if(st!=null){
            st.close();
          }
          if(con!=null){
            st.close();
          }
        }
         return bl;
       }
    }