package labexercise2;
import java.sql.*;
public class LabExercise2
{
public static void main (String [] args) throws SQLException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
System.out.println ("Driver Loaded");
Connection connection= DriverManager.getConnection("jdbc:mysql://localhost/restaurant?"+ "user=root&password=");
System.out.println ("Database connected");
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT MenuID, MenuName, Type, Cuisine FROM menu WHERE Price BETWEEN 7 AND 13");
while (rs.next()){
System.out.println(rs.getString("MenuID") + " : " +
rs.getString("MenuName") + " : " +
rs.getString("Type") + " : " +
rs.getString("Cuisine") + " : " +
rs.getString("Price")); }
connection.close();
}
}
我可以知道为什么它没有给出以下代码的输出,因为没有任何错误?我能知道为什么它没有给出以下代码的输出,因为没有任何错误?
任何帮助将不胜感激
你的意思是说,你不能看到表的字段,或没有的println工作???? – piyushj
它只显示运行: 驱动程序加载 数据库连接 在输出面板中建立成功(总时间:0秒)。我正在使用netbeans 8.1 –
我无法看到应在executeQuery()中执行的表的字段。前两个println成功显示 –