Advertisement
Guest User

Issue

a guest
Feb 9th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.sql.*;
  2. import javax.swing.JOptionPane;
  3.  
  4. public class Uppgift3 {
  5.  
  6. public static void main(String[] args) throws SQLException {
  7. Connection connect = null;
  8. PreparedStatement preState = null;
  9. ResultSet result = null;
  10.  
  11. try {
  12.  
  13. connect = DriverManager.getConnection("jdbc:mysql://localhost/Skola", "Zaher", "hej123");
  14. preState = connect.prepareStatement("SELECT Betyg FROM BetygVarde WHERE Varde=(SELECT ROUND(AVG(BetygVarde.Varde),0) FROM KursBetyg INNER JOIN BetygVarde ON KursBetyg.Betyg = BetygVarde.Betyg WHERE Kurskod= ?)");
  15. preState.setString(1, JOptionPane.showInputDialog("Välj Kurs"));
  16. preState.executeQuery();
  17. while (result.next()) {
  18. System.out.println(result.getString("Kurskod"));
  19. }
  20.  
  21. } catch (SQLException e) {
  22. e.printStackTrace();
  23. } finally {
  24. result.close();
  25. preState.close();
  26. connect.close();
  27. }
  28.  
  29. }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement