public ResultSet excuteQuery() { ResultSet resultSet = null; String sql = builder.toString(); clear(); try { resultSet = excutor.excuteQuery(sql); } catch (SQLException e) { // TODO: handle exception System.out.println("SQL语句有问题"); System.out.println(sql); e.printStackTrace(); } return resultSet; }
public boolean excute() { String sql = builder.toString(); clear(); try { excutor.excute(sql); return true; } catch (SQLException e) { // TODO Auto-generated catch block System.out.println("SQL语句有问题"); System.out.println(sql); e.printStackTrace(); return false; } }
public static void main(String[] args) { SQLBuilder sqlBuilder = new SQLBuilder(); // sqlBuilder.Select("T.account","T.balance").From("account").AS("T") // .Where("Balance").EQUALS(150).AND("Income").EQUALS(200); // System.out.println(sqlBuilder.getSQL()); // // sqlBuilder.clear(); // sqlBuilder.InsertInto("account", // "(balance,name,income)").Values("(15,100,'test')"); // System.out.println(sqlBuilder.getSQL()); // sqlBuilder.clear(); sqlBuilder.InsertInto("account").Values(15, 100, "test"); System.out.println(sqlBuilder.getSQL()); // sqlBuilder.clear(); sqlBuilder .Update("account") .Set("Name") .Assign("账户1") .Comma("balance") .Assign(12321.5) .Where("Income") .EQUALS(12345); System.out.println(sqlBuilder.getSQL()); // // sqlBuilder.clear(); // sqlBuilder.Update("account").Set("Name = '账户1'").Comma("balance = 12233") // .Where("Income = 12345"); // System.out.println(sqlBuilder.toString()); // // sqlBuilder.clear(); // sqlBuilder.DeleteFrom("account").Where("Name").EQUALS("账户1"); // System.out.println(sqlBuilder.getSQL()); sqlBuilder.handleString("2015-11-01"); System.out.println(sqlBuilder.getSQL()); sqlBuilder.clear(); sqlBuilder.handleString("2015-11-01 22:15:1"); System.out.println(sqlBuilder.getSQL()); sqlBuilder.clear(); Calendar calendar = Calendar.getInstance(); calendar.set(2015, 11, 11); sqlBuilder .Select("*") .From("stockoutorder") .Where("ins_id") .EQUALS("00110") .AND("time") .Between(calendar) .AND(calendar); System.out.println(sqlBuilder.toString()); sqlBuilder.clear(); sqlBuilder .InsertInto( PaymentListTable.tableName, PaymentListTable.paymentListID_col, PaymentListTable.total_col, PaymentListTable.payer_col, PaymentListTable.date_col, PaymentListTable.passed_col) .Values("11111", 50.3, "小春", Calendar.getInstance(), 0); System.out.println(sqlBuilder.toString()); sqlBuilder.clear(); sqlBuilder .Select("*") .From("billorder") .Where("time") .EQUALS("2015-11-26") .AND("order_id") .LIKE("0010001%"); System.out.println(sqlBuilder); sqlBuilder.clear(); }