2011-04-12 83 views

回答

1

use語句的作品,但因爲它是有狀態的,你必須確保它與後面的陳述是同一連接的一部分。

如果你使用Spring的JdbcTemplate,而不是與java.sql.Connectionjava.sql.Statement直接工作,你可以使用一個SingleConnectionDataSource

3

可以將「USE」命令作爲常規JDBC語句運行。

Statement stmt = connection.createStatement(); 
stmt.execute("USE the_other_db"); 

Dependending你的DBMS和驅動程序,您可能還可以使用JDBC API調用setCatalog():

connection.setCatalog("the_other_db")