Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
/**
*
*/
package de.tutorials;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
/**
* @author tom
*
*/
public class DatabaseCatalogExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Connection connection = initConnection();
DatabaseMetaData databaseMetaData = connection.getMetaData();
ResultSet resultSet = databaseMetaData.getCatalogs();
while (resultSet.next()) {
System.out.println(resultSet.getString("TABLE_CAT"));
}
resultSet.close();
connection.close();
}
private static Connection initConnection() throws Exception {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setUser("root");
dataSource.setPassword("");
dataSource.setServerName("localhost");
dataSource.setPort(3306);
dataSource.setDatabaseName("test");
return dataSource.getConnection();
}
}
/**
*
*/
package de.tutorials;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
/**
* @author Tom
*
*/
public interface IConnectionFactory {
Connection createConnection(String server, int port, String databaseName,
String username, String password, Map optionalArguments) throws SQLException;
}
/**
*
*/
package de.tutorials.impl;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Map;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import de.tutorials.IConnectionFactory;
/**
* @author Tom
*
*/
public class MySQLConnectionFactoryImpl implements IConnectionFactory{
public Connection createConnection(String server, int port, String databaseName, String username, String password, Map optionalArguments) throws SQLException{
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName(server);
dataSource.setPort(port);
dataSource.setDatabaseName(databaseName);
dataSource.setUser(username);
dataSource.setPassword(password);
return dataSource.getConnection();
}
}
/**
*
*/
package de.tutorials;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Properties;
/**
* @author Tom
*
*/
public class ConnectionFactoryExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
Properties properties = new Properties();
properties.load(ConnectionFactoryExample.class.getClassLoader()
.getResourceAsStream("database.properties"));
IConnectionFactory connectionFactory = (IConnectionFactory) Class
.forName(((String) properties.get("database.factory.class")))
.newInstance();
Connection connection = connectionFactory.createConnection("localhost", 3306, "test", "root", "", new HashMap());
//do something
connection.close();
}
}
database.factory.class=de.tutorials.impl.MySQLConnectionFactoryImpl
#database.factory.class=de.tutorials.impl.OracleConnectionFactoryImpl