Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.ResultSet;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. public class Part7 {
  8. public static void main(String[] args) {
  9. Statement stmt = null;
  10. ResultSet rs = null;
  11. Connection conn = null;
  12.  
  13. try {
  14. Class.forName("com.mysql.jdbc.Driver").newInstance();
  15.  
  16. conn = DriverManager.getConnection("jdbc:mysql://localhost/restaurant", "root", null);
  17.  
  18. stmt = conn.createStatement();
  19. rs = stmt.executeQuery("SELECT * FROM menu");
  20.  
  21. if (stmt.execute("SELECT * FROM menu")) {
  22. rs = stmt.getResultSet();
  23. }
  24. while (rs.next()) {
  25. System.out.println(rs.getString("Dish") + " = " + rs.getInt("Price"));
  26. }
  27. } catch (Exception e) {
  28. // TODO: handle exception
  29. }
  30. finally {
  31. try {
  32. rs.close();
  33. } catch (SQLException e) {
  34. // TODO Auto-generated catch block
  35. e.printStackTrace();
  36. }
  37. }
  38.  
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement