Join these together as:

```java
 String sqlVal = val
      .replace("%","\\%"); // Escape all % signs to preserve their meaning.
      .replace("*","%"); // Convert the * into non-escaped % signs.
```