我已经在MySQL中设置了我的表,并相信它们都正确连接,我只是想显示特定的信息。我要求用户输入并使用该整数值作为result.absolute()的对象。每当我运行timerresult输入时,我都会得到不正确的"actualtime"行。是java代码还是一些MySQL设置导致不正确的行显示?从println的所有其他信息是正确的。
public static void main(String[] args) throws Exception {
Scanner user_input = new Scanner( System.in );
String dayinput;
System.out.print("Choose A Day (1-7): ");
dayinput = user_input.next();
//Accessing driver from the JAR file
Class.forName("com.mysql.jdbc.Driver");
//Creating a variable for the connection called "con"
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/axamschedule","root","password");
//jdbc:mysql://localhost:3306/shows-----> This is the database
//root is the database username
//password is the database password
System.out.println("Connected To Database");
//Creating query for Sundays Table
if (dayinput.equals("1")){
PreparedStatement statement = con.prepareStatement("select * FROM suntimes, days, shows WHERE (days.idday = suntimes.idday and suntimes.idshow = shows.idshow)");
//Creating a variable to execute query
ResultSet result = statement.executeQuery();
System.out.println("---------------------");
Integer timeinput;
System.out.print("Choose A Timeslot (1-24): ");
timeinput = 0;
timeinput = user_input.nextInt();
if(result.absolute(timeinput)){
System.out.println("Time: " + result.getString("actualtime"));
System.out.println("Day: " + result.getString("day"));
System.out.println("Title: " + result.getString("title"));
System.out.println("Length: " + result.getString("length"));
System.out.println("Host: " + result.getString("author"));
}
}
user_input.close();
else{
System.out.println("No Info");
}
您得到的结果集没有排序。返回的顺序由mysql.
决定。试
select * FROM suntimes, days, shows WHERE (days.idday = suntimes.idday and suntimes.idshow = shows.idshow) order by actualtime;