Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.60 KB | None | 0 0
  1. package test2;
  2. //queries the books table in database wbluhm on multivac
  3.  
  4. import java.sql.*;
  5. import java.applet.*;
  6. import java.awt.*;
  7. public class testdatabse extends Applet {
  8.     /**
  9.      *
  10.      */
  11.     private static final long serialVersionUID = 1L;
  12.     public static class Global {
  13.         public static String A = null;
  14.         public static int H = 0;
  15. }
  16.     public void init(String A) {
  17.        
  18.         try {
  19.             Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  20.         }
  21.         catch (Exception E) {
  22.             System.err.println("Unable to load driver");
  23.             E.printStackTrace();
  24.         }
  25.  
  26.         try {
  27.             Connection C = DriverManager.getConnection(
  28.               "jdbc:mysql://localhost/marc","user","user123");
  29.             Statement Stmt = C.createStatement();
  30.  
  31.             ResultSet RS = Stmt.executeQuery
  32.             ("SELECT * From bezetting ");
  33.            
  34.             while(RS.next()){
  35.                 Global.A = Integer.toString(RS.getInt("dow"));
  36.                 Global.H = Global.H + 20;
  37.                 }
  38.             C.close();
  39.             RS.close();
  40.             Stmt.close();
  41.         }
  42.         catch (SQLException E) {
  43.             System.out.println("SQLException: " + E.getMessage());
  44.             System.out.println("SQLState:     " + E.getSQLState());
  45.             System.out.println("VendorError:  " + E.getErrorCode());
  46.         }
  47.        
  48.        
  49.     }
  50.  
  51.     public void stop(){/**/}
  52.     public void paint(Graphics g){
  53.         //method to draw text on screen
  54.         // String first, then x and y coordinate.
  55.      g.drawString(Global.A,20,Global.H);
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement