SHARE
TWEET

Untitled

a guest May 22nd, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class NavneVindu extends JFrame {
  2.  
  3.  
  4.     public void metode()
  5.     {
  6.         String dbdriver = "com.mysql.jdbc.Driver";
  7.         String server = "**********";
  8.         String database = "*******";
  9.         String bruker = "****";
  10.         String passord = "*****";
  11.  
  12.         Connection kobling = null;
  13.  
  14.         try {
  15.         Class.forName(dbdriver).newInstance();
  16.         kobling = DriverManager.getConnection("jdbc:mysql://" server "/" database, bruker, passord);
  17.         } catch (Exception ex) {
  18.         System.out.println("Feil! FÃ¥r ikke opprettet kontakt med databasen. ");
  19.         System.out.println(ex);
  20.         }
  21.  
  22.  
  23.         String sql = "select * from vare";
  24.         Statement stmt = null;
  25.         ResultSet res = null;
  26.         try {
  27.  
  28.         stmt = kobling.createStatement();
  29.  
  30.         res = stmt.executeQuery(sql);
  31.         } catch (SQLException ex) {
  32.         ex.printStackTrace();
  33.         }
  34.  
  35.         try {
  36.         while (res.next()) {
  37.  
  38.         String navn = res.getString("navn");
  39.  
  40.         System.out.println("" navn);
  41.         }
  42.         } catch (SQLException ex) {
  43.         ex.printStackTrace();
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top