我正在使用JDBC并使用MySqlDataSource进行连接。如何在DataSource.setDataBaseName()中添加模式名称之前创建模式?连接是可以的,我可以执行更新等等,但只有我在MysqlWorkbench中手动创建模式/数据库
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
public class DBHandler {
private String user = "root";
private String serverName = "localhost";
private String dbName = "TimeEdit";
private Connection connection;
private MysqlDataSource datasource = new MysqlDataSource();
public DBHandler(String passw) throws SQLException {
datasource.setPassword(passw);
datasource.setUser(user);
datasource.setServerName(serverName);
datasource.setDatabaseName(dbName);
//datasource.setURL("jdbc:mysql://<localhost>:<3306>/");
}
public Connection getConnection() throws SQLException {
return datasource.getConnection();
}