Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package dbaepackage;
- import java.io.BufferedWriter;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class JCDBtest {
- /**
- * @param args
- */
- public static void main(String[] args) {
- Connection con;
- String driver = "org.postgresql.Driver";
- String DB_SERVER = "obiwan-edu.iis.uni-hildesheim.de:5433";
- String DB_NAME = "DBAE_Gruppe_11";
- String password = "XQQR9hsH";
- String user = "dbgruppe11";
- String url = "jdbc:postgresql://" + DB_SERVER + "/" + DB_NAME;
- try {
- Class.forName(driver);
- con = DriverManager.getConnection(url, user, password);
- // Statement stmt = con.createStatement();
- // ResultSet rs = stmt
- // .executeQuery("select distinct(lied_titel) from lied");
- // PrintWriter pw = new PrintWriter("lied.txt");
- // String str = "";
- // while (rs.next()) {
- //
- // str = rs.getString(1);
- // System.out.println(str);
- // pw.println(str + "\n");
- // rs.next();
- // }
- // anfrage(con);
- htmlSeite();
- // pw.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static void anfrage(Connection con) {
- String gesucht = "Robbie Williams";
- try {
- PreparedStatement pstmt = con
- .prepareStatement("select name from person where nationalitaet = 'Deutschland'");
- //pstmt.setString(1, gesucht); //um ptsmt mit "?" auszuführen
- ResultSet rs = pstmt.executeQuery();
- while (rs.next()) {
- String str = rs.getString(1);
- System.out.println(str);
- }
- con.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- public static void htmlSeite() {
- try {
- FileWriter fw = new FileWriter("html.htm");
- BufferedWriter bw = new BufferedWriter(fw);
- bw.write("<html>");
- bw.write("\n<head>");
- bw.write("\n<title> MEINE SEITE </title>");
- bw.write("\n</head>");
- bw.write("\n<body bgcolor='blue'");
- bw.write("\n<p> HI SPASST</p>");
- bw.write("\n</body>");
- bw.write("\n</html>");
- bw.close();
- fw.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement