Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- public class Part7 {
- public static void main(String[] args) {
- Statement stmt = null;
- ResultSet rs = null;
- Connection conn = null;
- try {
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- conn = DriverManager.getConnection("jdbc:mysql://localhost/restaurant", "root", null);
- stmt = conn.createStatement();
- rs = stmt.executeQuery("SELECT * FROM menu");
- if (stmt.execute("SELECT * FROM menu")) {
- rs = stmt.getResultSet();
- }
- while (rs.next()) {
- System.out.println(rs.getString("Dish") + " = " + rs.getInt("Price"));
- }
- } catch (Exception e) {
- // TODO: handle exception
- }
- finally {
- try {
- rs.close();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement