Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void vytvorConnection() {
- String username ="student";
- String password ="Baterie15";
- String url ="jdbc:sqlserver://dbs.pf.jcu.cz;databaseName=TVUJ_NAZEV_DB";
- try {
- Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
- connection = DriverManager.getConnection(url, username,password);
- } catch (SQLException | ClassNotFoundException e) {
- System.err.println(e);
- }
- }
- public void dotaz(){
- try {
- String sql = "SELECT * FROM NazevTvojiTabulky";
- Statement stmt = connection.createStatement();
- ResultSet result = stmt.executeQuery(sql);
- while (result.next()) {
- // např. když tam bude sloupec Nazev tak: String nazev = result.getString("Nazev");
- // ....
- }
- } catch (SQLException e) {
- System.err.println(e);
- }
- }
- // v kodu potom jen:
- // vytvorConnection();
- // dotaz();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement