There are some limitations of using JDBC and database dependency is one of those limitations.
Is there any pattern or way to achieve database independence in JDBC (w
Firstly, database independence is hard. Really, really hard; to achieve it without using an ORM or other tool, you will have to trade some other aspect of your solution design. Simplicity and maintainability will suffer, as will the effort to implement the solution.
So, I'd make really, really sure that this is a high priority requirement - a hypothetical "what if we want to switch from Oracle to SQL Server" question is - in my opinion - not sufficient justification to incur the additional costs...
If you must deliver this feature, and ORM is by far the easiest way to do it. The ORM frameworks are specifically designed with database independence in mind (and their complexity is at least in part due to that requirement). They do so by abstracting away the database implementation into a higher level; instead of thinking in SQL statements, you're encouraged to think about domain objects.
Having said all that...
I have delivered a solution (not in Java, but the principle stands) which allowed database independence. We stored our SQL statements as resources, and loaded them via resource files. The default was ANSI SQL, which should work on any modern SQL-compatible database.
We had resource files for each database flavour we supported (in our case MySQL and Oracle), and used overrides to load in database-specific SQL statement if they existed.
This works like internationalization in most languages - look for locale-specific strings first, fall back to default if you can't find one.
Java's resource bundle would make this pretty easy. Not hardcoding your SQL in your application has other benefits - fixing a database problem without changing the application code is much easier, you can deploy fixes as "resource" updates rather than shipping a new binary etc.