Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package testi;
- /**
- *
- * @author aleks
- */
- import java.sql.*;
- public class Testi {
- // tietokannan ja käyttäjän tiedot
- // private static final String AJURI = "org.postgresql.Driver";
- private static final String PROTOKOLLA = "jdbc:postgresql:";
- private static final String PALVELIN = "dbstud2.sis.uta.fi";
- private static final int PORTTI = 5432;
- private static final String TIETOKANTA = "al424411"; // tähän oma käyttäjätunnus
- private static final String KAYTTAJA = "al424411"; // tähän oma käyttäjätunnus
- private static final String SALASANA = "666"; // tähän tietokannan salasana
- public static void main(String args[]) {
- Connection con = null;
- try {
- con = DriverManager.getConnection(PROTOKOLLA + "//" + PALVELIN + ":" + PORTTI + "/" + TIETOKANTA, KAYTTAJA, SALASANA);
- PreparedStatement updateArvosana = con.prepareStatement("UPDATE YK.suoritukset SET arvosana 3" +
- "WHERE arvosana = 5");
- ResultSet rset = updateArvosana.executeQuery();
- updateArvosana.close(); // sulkee automaattisesti myös tulosjoukon rset
- } catch (SQLException poikkeus) {
- // Vaihe 3.2: tähän toiminta mahdollisessa virhetilanteessa
- System.out.println("Tapahtui seuraava virhe: " + poikkeus.getMessage());
- }
- // Vaihe 4: yhteyden sulkeminen
- if (con != null) try { // jos yhteyden luominen ei onnistunut, con == null
- con.close();
- } catch(SQLException poikkeus) {
- System.out.println("Yhteyden sulkeminen tietokantaan ei onnistunut. Lopetetaan ohjelman suoritus.");
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement