yes, there are 2 ways
proper way been to use the necessary API of the db or the classes that come with java to run and access the DB [like mysql and oracle]

other way it to directly run the necessary console (for ex if mysql is installed in the server you can run the commanline of mysql and run any command through it)
this way is easier because you can directly output the output given by the commandline itself