Q:

netbeans mysql syntax Error at line 1 and no error in mysql query browser

Hi I have a netbeans problem, I am Updating my database with a couple queries, only one runs the second query is giving a syntax problem when the query runs perfectly in mysql query browser. here is the code in netbeans: 
try{

    String Query = "select nr,linkid,transdate,amount,type from astpay"
                + "where type = 'all' or 'cash';";
        Statement ps = test.createStatement();
        ResultSet rs = ps.executeQuery(Query);
        //if there are payments that fit the criteria
        if(rs.next()){
        //while loop to generatepremuim for the cash payments
            while(rs.next()){
                System.out.println("Now to generate the premuim for the cash payments...");
                Query = "insert into astpay" +
                   "(linkid,branchno,transdate,amount,refno,month,year,type)" +
                   "select a.linkid,a.branchno, a.transdate, a.amount, a.refno, a.month,a.year, p.paytype" +
                   "from astpay a, astpaytype p" +
                   "where(a.type ='all' or a.type ='cash' or a.type ='debit')" +
                   "and p.paytype = 'prem';";
               ps = test.createStatement();
               ps.execute(Query);

        }
        }else{
            System.out.println("There was a an error generating the Premuims for Cash payments....");

        }
   }catch(SQLException exp){
    System.err.println("Failed to execute the statement!");
    System.err.println(exp.getMessage());

   }

} 
here is the mysql code for the same string which runs in mysql query browser: 
`insert into astpay (linkid,branchno,transdate,amount,refno,month,year,type) select a.linkid,a.branchno, a.transdate, a.amount, a.refno, a.month,a.year, p.paytype from astpay a, astpaytype p where (a.type = 'all' or a.type ='cash' or a.type = 'debit') and p.paytype = 'prem';`

here is the error returned in netbeans: 
Failed to execute the statement!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= 'all' or 'cash'' at line 1

here
I have tried a lot of things to get it to work and I do not know where I went wrong. I am hoping someone else may be able to help, which will be greatly appreciated. 

A:

Use ps.executeUpdate instead of ps.execute. And add a join beetween tables astpay and astpaytype (or use explicit cross join if you it is that you want)
Your error :
change 
where type = 'all' or 'cash'

to
where type = 'all' or type = 'cash'

or
where type in ('all' ,'cash')

Your second error : add space before where :
 Query = "insert into astpay" +
                   "(linkid,branchno,transdate,amount,refno,month,year,type)" +
                   "select a.linkid,a.branchno, a.transdate, a.amount, a.refno, a.month,a.year, p.paytype" +
                   "from astpay a, astpaytype p" +
                   " where(a.type ='all' or a.type ='cash' or a.type ='debit')" +
                   " and p.paytype = 'prem';";

your code produce "...from astpay a, astpaytype pwhere(a.type ='all' or ..."

