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 org.hsqldb.Server;
import org.hsqldb.ServerConfiguration;
import org.hsqldb.persist.HsqlProperties;
/**
* @author daritho
*
*/
public class HSQLDBStarterExample {
/**
* @param args
*/
public static void main(String[] args) {
String[] options = new String[] { "-database.0 mydb", "-dbname.0", "xdb" };
// // Entweder:
// Server.main(options);
// Oder:
HsqlProperties hsqlproperties = HsqlProperties.argArrayToProps(
options,
"server");
ServerConfiguration.translateDefaultDatabaseProperty(hsqlproperties);
ServerConfiguration
.translateDefaultNoSystemExitProperty(hsqlproperties);
Server server = new Server();
server.setProperties(hsqlproperties);
server.start();
}
}
/**
*
*/
package de.tutorials;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import org.hsqldb.Server;
import org.hsqldb.jdbc.jdbcDataSource;
/**
* @author Tom
*
*/
public class HSQLDBStarterExample {
/**
* @param args
*/
public static void main(String[] args) {
Server server = new Server();
server.setDatabaseName(0, "tutorials");
server.setDatabasePath(0, "c:/tmp/tutorials.db");
server.start();
// insertTestData();
readTestData();
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
shutdownDataBase();
}
private static void shutdownDataBase() {
jdbcDataSource dataSource = setupDataSource();
try {
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
statement.execute("SHUTDOWN");
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static void readTestData() {
jdbcDataSource dataSource = setupDataSource();
try {
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery("SELECT * FROM test");
statement.close();
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int columnCount = resultSetMetaData.getColumnCount();
while (resultSet.next()) {
for (int i = 1; i <= columnCount; i++) {
System.out.print(resultSet.getString(i) + " ");
}
System.out.println();
}
resultSet.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static void insertTestData() {
jdbcDataSource dataSource = setupDataSource();
try {
Connection connection = dataSource.getConnection();
Statement statement = connection.createStatement();
System.out.println("Insert testdata");
statement.execute("CREATE TABLE test (id int, data varchar(32))");
statement.execute("INSERT INTO test (id, data) VALUES (1,'aaaa')");
statement.close();
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
private static jdbcDataSource setupDataSource() {
jdbcDataSource dataSource = new jdbcDataSource();
dataSource.setDatabase("jdbc:hsqldb:file:/tmp/tutorials.db");
dataSource.setUser("sa");
dataSource.setPassword("");
return dataSource;
}
}