用ecilpse 和SQL Server2005数据库联合做的项目思路

解决方案 »

  1.   

    我大概帮你写了一下程序的思路:
    先写对象类public class Student {
    String studentName ;
    String studentId;
    //等等学生属性,注意与数据库中t_student表的属性要相同
    }
    public class Admin {
    String adminName;
    String adminId;
    //等等各种管理员属性,与数据库表t_admin属性相同
    }
    public class Book {
    String bookName ;
    String bookId;
    //等等...书籍属性,与数据库中t_book表属性相同
    }
    public class Borrowlist {
    int id;
    int bookId;
    int studentId;
    //等等...借书属性,与数据库数据t_borrowlist相同
    }
    再写主程序public class Te {
    public static void main(String[] args) {
    Menu menu = new Menu();
    menu.menu1();//导入程序入口
    }
    }
    import java.util.Scanner;
    public class Menu {
    Jdbc jdbc = new Jdbc();//用jdbc来调用Jdbc中的方法,实现与数据库的沟通
    Scanner input = new Scanner(System.in);
    //主菜单
    public void menu1(){
        int i = input.nextInt();
    switch(i){
    case 1:
    xxx();//通过选择转到子菜单xxx
    case 2:
    XXX();//转到XXX
    //省略........
    }
    }
    private void xxx(){
    //写xxx的借书方法,大概如下:
    System.out.println("请输入studetid");
    int stu = input.nextInt();
    System.out.println("请输入bookid");
    int book = input.nextInt();
    jdbc.borrowBook(stu, book);//调用jdbc中的方法把stu和book保存到数据库中了
    }
    private void XXX() {
    //写XXX的方法
    }
    //省略.........
    }
    //这是一个与数据库相连的类,里面含有各种操作数据库的方法
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    public class Jdbc {
    /**
     * 这是一个借书的方法,把bookid和studentid写入t_borrowlist中
     * @return 返回数据库受影响的行数
     * @throws Exception //try/catch自己添
     */
    public int borrowBook(int studentid,int bookid) throws Exception{
    Class.forName("加载数据库驱动");
    Connection con = DriverManager.getConnection("URL信息", "用户名", "密码");
    String str = "insert into t_borrowlist(bookid,studentid) values(bookid,studentid);";
    PreparedStatement pre = con.prepareStatement(str);
    int i = pre.executeUpdate();//在数据库中执行sql语句,返回受影响的行数~~
    pre.close();//释放内存.......
    con.close();//释放内存.......
    return i;
    }
    //其他方法自己动手省略.............
    }
    只是大概帮你写了一下思路,你最好多多动手。。