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.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.jdbc.driver.OracleDriver;
import oracle.jdbc.pool.OracleDataSource;
//gibt von der Employee Datenbank die ganze Tabelle aus...
class GetSelect
{
public static void main(String[] args)
{
String user = "hr";
String password = "fenerium";
String host = "localhost";
String port = "1521";
String dbService = "xe";
String thinDriverPrefix = "jdbc:oracle:thin";
String thinConnectURL = thinDriverPrefix + ":" + user + "/" +
password + "@" + host+ ":" + port + ":" +dbService;
// the String value = "jdbc:oracle:thin:hr/fenerium@rmenon-lap:1521:ora10g";
System.out.println("Database connect url: " + thinConnectURL);
System.out.print("Establishing connection to the database ");
ResultSet rset = null;
Connection conn = null;
Statement stmt = null;
try
{
//instantiate and initialize OracleDataSource
OracleDataSource ods = new OracleDataSource();
ods.setURL(thinConnectURL );
// get the connection
conn = ods.getConnection();
System.out.println("Connected.\nPrinting query results....\n");
//Next we create a Statement object
stmt = conn.createStatement();
//hier wir der Select Befehl ausgeführt
//Datenbank wird hier rausgelesen
rset = stmt.executeQuery("SELECT EMPLOYEE_ID, LAST_NAME,FIRST_NAME,EMAIL, " +
"PHONE_NUMBER, DEPARTMENT_ID, JOB_ID, MANAGER_ID FROM employees " +
"WHERE DEPARTMENT_ID = 50 " +
"AND MANAGER_ID = 120");
// declare constants for column indexes in the query
final int EMPLOYEE_COLUMN_INDEX = 1;
final int LAST_COLUMN_INDEX = 2;
final int FIRST_COLUMN_INDEX = 3;
final int EMAIL_COLUMN_INDEX = 4;
final int PHONE_COLUMN_INDEX = 5;
final int DEP_COLUMN_INDEX = 6;
final int JOB_COLUMN_INDEX = 7;
final int MANAGER_COLUMN_INDEX = 8;
//print the results
while (rset.next())
{
int employee = rset.getInt(EMPLOYEE_COLUMN_INDEX);
String lastName = rset.getString(LAST_COLUMN_INDEX);
String firstName = rset.getString(FIRST_COLUMN_INDEX);
String emailName = rset.getString(EMAIL_COLUMN_INDEX);
String phoneName = rset.getString(PHONE_COLUMN_INDEX);
int depName = rset.getInt(DEP_COLUMN_INDEX);
String jobName = rset.getString(JOB_COLUMN_INDEX);
int manName = rset.getInt(MANAGER_COLUMN_INDEX);
System.out.println(employee + " " + lastName + " " + firstName
+ " " + emailName+ " "+ phoneName+ " "+depName+" "+jobName+" "+manName);
}
}
catch (SQLException e)
{
// handle the exception properly - in this case, we just
// print a message and stack trace and exit the application
System.err.println("error messgae: " + e.getMessage());
e.printStackTrace();
Runtime.getRuntime().exit(1);
}
finally
{
// close the result set, statemnt, and connection.
// ignore any exceptions since we are in the finally clause.
try
{
if(rset != null)
rset.close();
if(stmt != null)
stmt.close();
if(conn != null)
conn.close();
}
catch (SQLException ignored) {ignored.printStackTrace();}
}
}
}