问题描述
- 哪位大神帮忙解决一下Keyboard cannot be resolved的问题
-
具体代码如下
package Students;
import java.sql.*;
import java.util.ArrayList;
public class Test
{
private String id;
private String name;
private int math;
private int english;
private int java;
private int computer;public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getMath() { return math; } public void setMath(int math) { this.math = math; } public int getEnglish() { return english; } public void setEnglish(int english) { this.english = english; } public int getJava() { return java; } public void setJava(int java) { this.java = java; } public int getComputer() { return computer; } public void setComputer(int computer) { this.computer = computer; } public static void main(String[] args) throws Exception { String id; String cid; String name; int math; int english; int java; int computer; String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; String conStr = "jdbc:odbc:student"; Connection con = null; Statement stmt = null; ResultSet rs = null; Class.forName(DBDriver); con = DriverManager.getConnection(conStr, "student", "123"); stmt = con.createStatement(); String s = "nnttt学 生 成 绩nntt 1 新 增ntt 2 更 改ntt 3 删 除ntt 4 查 找ntt 5 显 示ntt 0 退 出nn"; System.out.print(s); int choice = Keyboard.getInteger(); switch (choice) { // 添加学生 case 1: System.out.print("请输入学生信息n"); System.out.print("学号:"); id = Keyboard.getString(); System.out.print("姓名:"); name = Keyboard.getString(); System.out.print("数学:"); math = Keyboard.getInteger(); System.out.print("英语:"); english = Keyboard.getInteger(); System.out.print("JAVA:"); java = Keyboard.getInteger(); System.out.print("计算机:"); computer = Keyboard.getInteger(); stmt.executeUpdate("insert into lxh1 values('" + id + "','" + name + "','" + math + "','" + english + "','" + java + "','" + computer + "')"); System.out.println("n添加完成。"); break; // 更改成绩 case 2: System.out.println("请输入要改的学生学号:"); cid = Keyboard.getString(); System.out.println("数学:"); math = Keyboard.getInteger(); System.out.println("英语:"); english = Keyboard.getInteger(); System.out.println("JAVA:"); java = Keyboard.getInteger(); System.out.println("计算机:"); computer = Keyboard.getInteger(); stmt.executeUpdate("update lxh1 set math='" + math + "',english='" + english + "',java='" + java + "',computer='" + computer + "' where sno=" + cid + ""); System.out.println("n修改完成"); break; // 删除指定学生 case 3: System.out.println("请输入要改的学生学号:"); cid = Keyboard.getString(); stmt.executeUpdate("delete from lxh1 where sno=" + cid + ""); System.out.println("n删除完成"); break; // 显示指定学生 case 4: System.out.println("请输入查找的学生学号:"); cid = Keyboard.getString(); System.out.println("n" + cid + "号学生信息nn学号t姓名t数学t英语tJAVAt计算机t"); rs = stmt.executeQuery("select * from lxh1 where sno=" + cid + ""); while (rs.next()) { System.out.println(rs.getInt("sno") + "t" + rs.getString("sname") + "t" + rs.getString("math") + "t" + rs.getString("english") + "t" + rs.getString("java") + "t" + rs.getString("computer") + "t"); } break; case 5: // 输出全部信息 System.out.println("n全部学生信息nn学号t姓名t数学t英语tJAVAt计算机t平均成绩"); rs = stmt.executeQuery("select * from lxh1 order by math desc"); while (rs.next()) { int a = rs.getInt("math"); int b = rs.getInt("english"); int c = rs.getInt("java"); int d = rs.getInt("computer"); System.out.println(rs.getString("sno") + "t" + rs.getString("sname") + "t" + a + "t" + b + "t" + c + "t" + d + "t" + ((a + b + c + d) / 4)); } ; // 输出平均分 System.out.println("n各科平均分nn数学t英语tJAVAt计算机t"); rs = stmt .executeQuery("select avg(math),avg(english),avg(java),avg(computer) from lxh1"); while (rs.next()) { System.out.println(rs.getInt(1) + "t" + rs.getInt(2) + "t" + rs.getInt(3) + "t" + rs.getInt(4)); } ; // 输出最高分 System.out.println("n各科最高分nn数学t英语tJAVAt计算机t"); rs = stmt.executeQuery("select max(math),max(english),max(java),max(computer) from lxh1"); while (rs.next()) { System.out.println(rs.getInt(1) + "t" + rs.getInt(2) + "t" + rs.getInt(3) + "t" + rs.getInt(4)); } ; // 输出最低分 System.out.println("n各科最低分nn数学t英语tJAVAt计算机t"); rs = stmt .executeQuery("select min(math),min(english),min(java),min(computer) from lxh1"); while (rs.next()) { System.out.println(rs.getInt(1) + "t" + rs.getInt(2) + "t" + rs.getInt(3) + "t" + rs.getInt(4)); } ; break; case 0: break; default: System.out.println("感谢您的使用,再见!"); } ; stmt.close(); con.close(); }
}
解决方案
需要导入java.io
import java.io.*;
http://www.cnblogs.com/xuxm2007/archive/2011/10/20/2219104.html
解决方案二:
应该是引入的Jar包不全引起的
时间: 2024-12-30 08:41:34