精华内容
下载资源
问答
  • 二、Java的类用到的类: DBUtil(连接、关闭数据库)、Student(学生信息)、Userdemo(接口:实现Student表的增删该查)、UserdemoImpl(实现Userdemo接口里的方法)、Test(测试台);1、Student//Student表publ...

    一、Studnet表:

    属性:sno int(20)、cno int(4)、grade int(4)。即学号、课程号、成绩。

    二、Java中的类

    用到的类: DBUtil(连接、关闭数据库)、Student(学生信息)、Userdemo(接口:实现Student表的增删该查)、UserdemoImpl(实现Userdemo接口里的方法)、Test(测试台);

    1、Student

    //Student表

    public class Student

    {

    private int sno;

    private int cno;

    private int grade;

    public Student(int sno, int cno, int grade)

    {

    this.sno = sno;

    this.cno = cno;

    this.grade = grade;

    }

    public Student()

    {

    }

    public String toString()

    {

    return this.sno+","+this.cno+","+this.grade;

    }

    public int getSno()

    {

    return sno;

    }

    public void setSno(int sno)

    {

    this.sno = sno;

    }

    public int getCno()

    {

    return cno;

    }

    public void setCno(int cno)

    {

    this.cno = cno;

    }

    public int getGrade()

    {

    return grade;

    }

    public void setGrade(int grade)

    {

    this.grade = grade;

    }

    }

    2、DBUtil

    import java.io.*;

    import java.util.*;

    import java.sql.*;

    public class DBUtil

    {

    private static String driver = "com.mysql.cj.jdbc.Driver"; //用于加载驱动

    private static String url = "jdbc:mysql://localhost:3306/sc3?serverTimezone=UTC"; //数据库地址

    private static String username = "root"; //用户名

    private static String password = "123456"; //密码

    //连接数据库

    public static Connection open()

    {

    try

    {

    Class.forName(driver); //加载驱动

    return DriverManager.getConnection(url, username, password);

    } catch (Exception e)

    {

    e.printStackTrace();

    }

    return null;

    }

    //关闭数据库

    public static void close(Connection conn)

    {

    if(conn!=null)

    {

    try

    {

    conn.close();

    } catch (SQLException e)

    {

    e.printStackTrace();

    }

    }

    }

    }

    3、Userdemo

    import java.util.ArrayList;

    //实现对数据库中sc表的增、删、改、查

    public interface Userdemo

    {

    public void Insert(Student s);

    public void Delete(int sno,int cno);

    public void Update(Student s);

    public Student Get(int sno,int cno);

    public ArrayListSelectAll();

    }

    4、UserdemoImpl

    import java.util.*;

    import java.sql.*;

    public class UserdemoImpl implements Userdemo //实现Userdemo接口的方法

    {

    @Override

    public void Insert(Student s) //增

    {

    //链接数据库

    Connection conn = DBUtil.open();

    //创建语句

    String sql = "insert into sc values(?,?,?)";

    try

    {

    //动态操作sql语句

    PreparedStatement pstmt = conn.prepareStatement(sql);

    pstmt.setInt(1,s.getSno());

    pstmt.setInt(2,s.getCno());

    pstmt.setInt(3,s.getGrade());

    pstmt.executeUpdate();

    } catch (SQLException e)

    {

    e.printStackTrace();

    }

    finally

    {

    DBUtil.close(conn); //关闭数据库

    }

    }

    @Override

    public void Delete(int sno, int cno) //删

    {

    Connection conn = DBUtil.open();

    String sql = "delete from sc where sno=? and cno=?";

    try

    {

    PreparedStatement pstmt = conn.prepareStatement(sql);

    pstmt.setInt(1,sno);

    pstmt.setInt(2,cno);

    pstmt.executeUpdate();

    } catch (SQLException e)

    {

    e.printStackTrace();

    }

    finally

    {

    DBUtil.close(conn);

    }

    }

    @Override

    public void Update(Student s) //改

    {

    Connection conn = DBUtil.open();

    String sql = "update sc set grade=? where sno=? and cno=?";

    try

    {

    PreparedStatement pstmt = conn.prepareStatement(sql);

    pstmt.setInt(1,s.getGrade());

    pstmt.setInt(2,s.getSno());

    pstmt.setInt(3,s.getCno());

    pstmt.executeUpdate();

    } catch (Exception e)

    {

    e.printStackTrace();

    }

    finally

    {

    DBUtil.close(conn);

    }

    }

    @Override

    public Student Get(int sno, int cno) //查

    {

    Connection conn = DBUtil.open();

    String sql = "select grade from sc where sno=? and cno=?";

    try

    {

    PreparedStatement pstmt = conn.prepareStatement(sql);

    pstmt.setInt(1,sno);

    pstmt.setInt(2,cno);

    ResultSet rs = pstmt.executeQuery();

    if(rs.next())

    {

    int grade = rs.getInt(1);

    Student s = new Student(sno,cno,grade);

    return s;

    }

    } catch (Exception e)

    {

    e.printStackTrace();

    }

    finally

    {

    DBUtil.close(conn);

    }

    return null;

    }

    @Override

    public ArrayListSelectAll() //遍历

    {

    ArrayListstu = new ArrayList();

    Connection conn = DBUtil.open();

    String sql = "select * from sc";

    try

    {

    Statement stmt = conn.createStatement();

    ResultSet rs = stmt.executeQuery(sql);

    while(rs.next())

    {

    int sno = rs.getInt(1);

    int cno = rs.getInt(2);

    int grade = rs.getInt(3);

    Student s = new Student(sno,cno,grade);

    stu.add(s);

    }

    return stu;

    } catch (SQLException e)

    {

    e.printStackTrace();

    }

    finally

    {

    DBUtil.close(conn);

    }

    return null;

    }

    }

    5、Test

    import java.util.*;

    import java.sql.*;

    public class Test

    {

    public static void Create() //创建Student表

    {

    Connection conn = DBUtil.open(); //连接数据库

    String sql = "create table student(sno int(20),cno int(4),grade int(4),primary key(sno,cno))";

    try

    {

    Statement stmt = conn.createStatement(); //静态操作sql语句

    stmt.execute(sql);

    } catch (SQLException e)

    {

    e.printStackTrace();

    }

    finally

    {

    DBUtil.close(conn);

    }

    }

    public static void show() //提示信息

    {

    System.out.println("***********成绩数据库管理***********");

    System.out.println("insert: 插入成绩.");

    System.out.println("delete: 删除成绩.");

    System.out.println("update: 更新成绩.");

    System.out.println("get: 查看成绩.");

    System.out.println("list: 查看所有成绩.");

    System.out.println("***********成绩数据库管理***********");

    }

    public static void main(String[] args)

    {

    Scanner in = new Scanner(System.in);

    //Create();

    Userdemo userdemo = new UserdemoImpl(); //多态

    Student stu = new Student();

    while(true)

    {

    show();

    System.out.print("命令>");

    String s = in.next();

    if(s.equals("insert"))

    {

    System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");

    System.out.print("请输入学号:");

    int sno = in.nextInt();

    System.out.print("请输入课程号:");

    int cno = in.nextInt();

    System.out.print("请输入成绩:");

    int grade = in.nextInt();

    stu.setSno(sno);

    stu.setCno(cno);

    stu.setGrade(grade);

    userdemo.Insert(stu);

    }

    else if(s.equals("delete"))

    {

    System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");

    System.out.print("请输入待删除的学号:");

    int sno = in.nextInt();

    System.out.print("请输入待删除的课程号:");

    int cno = in.nextInt();

    userdemo.Delete(sno, cno);

    }

    else if(s.equals("update"))

    {

    System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");

    System.out.print("请输入待更新的学号:");

    int sno = in.nextInt();

    System.out.print("请输入待更新的课程号:");

    int cno = in.nextInt();

    System.out.print("请输入新成绩:");

    int grade = in.nextInt();

    stu.setSno(sno);

    stu.setCno(cno);

    stu.setGrade(grade);

    userdemo.Update(stu);

    }

    else if(s.equals("get"))

    {

    System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");

    System.out.print("请输入查询的学号:");

    int sno = in.nextInt();

    System.out.print("请输入查询的课程号:");

    int cno = in.nextInt();

    stu = userdemo.Get(sno, cno);

    System.out.println("成绩:"+stu.getGrade());

    }

    else if(s.equals("list"))

    {

    ArrayListnote = userdemo.SelectAll();

    for(int i=0,t=note.size();i

    展开全文
  • C程序SQLite数据库中创建表并插入数据 (C programs to create table & insert data in SQLite database) Here, will create a "SCHOOL.db" database, create a table "STUDENT" and insert data using c ...

    C程序在SQLite数据库中创建表并插入数据 (C programs to create table & insert data in SQLite database)

    Here, will create a "SCHOOL.db" database, create a table "STUDENT" and insert data using c program.

    在这里,将创建一个“ SCHOOL.db”数据库,创建一个表“ STUDENT”并使用c程序插入数据。

    #include <sqlite3.h>
    #include <stdio.h>
    
    int main(void) 
    {
        
        sqlite3 * dbPtr;
        char *errMsg = 0;
        
        int rec = sqlite3_open("SCHOOL.db", & dbPtr);
        
        if (rec != SQLITE_OK) 
        {        
            printf("Database cannot Opened: %s\n", sqlite3_errmsg(dbPtr));
            sqlite3_close(dbPtr);
            
            return 1;
        }
        
        char *sql = "DROP TABLE IF EXISTS STUDENT;" 
                    "CREATE TABLE STUDENT(rollNum INT, Name TEXT, Section varchar );" 
                    "INSERT INTO STUDENTS VALUES(1, 'Arvind', 'A');" 
                    "INSERT INTO STUDENT VALUES(2, 'Amit', 'C');" 
                    "INSERT INTO STUDENT VALUES(3, 'Shivang', 'A');" 
                    "INSERT INTO STUDENT VALUES(4, 'RAGHU', 'A');" 
                    "INSERT INTO STUDENT VALUES(5, 'SACHIN', 'C');" 
                    "INSERT INTO STUDENT VALUES(6, 'HITEN', 'B');";
    
        rec = sqlite3_exec(dbPtr, sql, 0, 0, & errMsg);
        
        if (rec != SQLITE_OK ) {
            
            printf("SQL error: %s\n", errMsg);
            
            sqlite3_free(errMsg);        
            sqlite3_close(dbPtr);
            
            return 1;
        } 
        
        sqlite3_close(dbPtr);    
        return 0;
    }
    
    

    In the above example, we are connecting to database "SCHOOL.db" database, if the database is already created into the database, if the database is not created in SQLITE3 database then an error message will be prompt on display screen.

    在上面的示例中,我们正在连接到数据库“ SCHOOL.db”数据库,如果该数据库已经创建到数据库中,如果未在SQLITE3数据库中创建该数据库,则会在显示屏幕上提示错误消息。

    If we connected successfully to the database then we STUDENT table will be created automatically, we table is already created into the database then it drops the table and creates the table again.

    如果我们成功连接到数据库,那么我们的STUDENT表将自动创建,我们的表已经创建到数据库中,然后删除该表并再次创建该表。

    char *sql = 
    	"DROP TABLE IF EXISTS STUDENT;" 
    	"CREATE TABLE STUDENT(rollNum INT, Name TEXT, Section varchar );" 
    	"INSERT INTO STUDENTS VALUES(1, 'Arvind', 'A');" 
    	"INSERT INTO STUDENT VALUES(2, 'Amit', 'C');" 
    	"INSERT INTO STUDENT VALUES(3, 'Shivang', 'A');" 
    	"INSERT INTO STUDENT VALUES(4, 'RAGHU', 'A');" 
    	"INSERT INTO STUDENT VALUES(5, 'SACHIN', 'C');" 
    	"INSERT INTO STUDENT VALUES(6, 'HITEN', 'B');";
    
    

    In the above code, we made a string that contains CREATE and INSERT and DROP statements. Here we are inserting 6 rows into STUDENT table. Here all statements are separated by a semicolon.

    在上面的代码中,我们创建了一个包含CREATEINSERTDROP语句的字符串。 在这里,我们将6行插入到STUDENT表中。 在这里,所有语句都用分号分隔。

        rec = sqlite3_exec(dbPtr, sql, 0, 0, & errMsg);
    
    

    In the above statement, we are using sqlite3_exec() function to execute SQL queries into the SQLite database.

    在上面的语句中,我们使用sqlite3_exec()函数对SQLite数据库执行SQL查询。

    If the given SQL statement is not incorrect format. Then it produces an error message.

    如果给定SQL语句格式不正确。 然后,它会生成一条错误消息。

        sqlite3_free(errMsg);
    
    

    Then above function will free errMsg.

    然后上述功能将释放errMsg 。

    Now come to terminal to check data is inserted into the database or not? First, we set console mode and on the header to see headers of the table.

    现在到终端检查数据是否插入数据库? 首先,我们设置控制台模式,并在标题上查看表的标题。

    sqlite> .mode column  
    sqlite> .headers on
    
    sqlite> SELECT * FROM STUDENT;
    
    rollNum       Name        Section     
    ----------  ----------  ----------
    1		Arvind		A
    2		Amit		C
    3		Shivang		A
    4		RAGHU		A
    5		SACHIN		C
    6		HITEN		B 
    
    

    The above data is written into STUDENT table of "SCHOOL.db" database.

    将以上数据写入“ SCHOOL.db”数据库的STUDENT表中。

    如何知道最后插入的行ID? (How to know last inserted row id?)

    Sometimes we required what is the last inserted row id into the database table? Here in the below code, we will get last inserted row id using c program.

    有时我们需要在数据库表中最后插入的行ID是什么? 在下面的代码中,我们将使用c程序获取最后插入的行ID。

    #include <sqlite3.h>
    #include <stdio.h>
    
    int main(void) 
    {
        
        sqlite3 * dbPtr;
        char *errMsg = 0;
        
        int rec = sqlite3_open("SCHOOL.db", & dbPtr);
        
        if (rec != SQLITE_OK) 
        {        
            printf("Database cannot Opened: %s\n", sqlite3_errmsg(dbPtr));
            sqlite3_close(dbPtr);
            
            return 1;
        }
        
        char *sql = "DROP TABLE IF EXISTS STUDENT;" 
                    "CREATE TABLE STUDENT(id INT PRIMARY KEY, Name TEXT, Section varchar );" 
                    "INSERT INTO STUDENTS VALUES('Arvind', 'A');" 
                    "INSERT INTO STUDENT VALUES('Amit', 'C');" 
                    "INSERT INTO STUDENT VALUES('Shivang', 'A');" 
                    "INSERT INTO STUDENT VALUES('RAGHU', 'A');" 
                    "INSERT INTO STUDENT VALUES('SACHIN', 'C');" 
                    "INSERT INTO STUDENT VALUES('HITEN', 'B');";
        
        rec = sqlite3_exec(dbPtr, sql, 0, 0, & errMsg);
        
        if (rec != SQLITE_OK )
        {
            printf("SQL error: %s\n", errMsg);
            sqlite3_free(errMsg);        
        } 
        else 
        {    
            printf("Table STUDENT created successfully\n");
        }
        
        int lastId = sqlite3_last_insert_rowid(dbPtr);
        printf("Last inserted row id is %d\n", lastId);
    
        sqlite3_close(dbPtr);
        
        return 0;
    }
    
    

    Here, "STUDENT" table is created and id column is automatically incremented.

    在此,将创建“ STUDENT”表,并且id列会自动增加。

        int lastId = sqlite3_last_insert_rowid(dbPtr);
    
    

    In above statement, sqlite3_last_insert_rowid() function is used to get last inserted row id, it returns integer value.

    在上面的语句中, sqlite3_last_insert_rowid()函数用于获取最后插入的行id ,它返回整数值。

    Reference: http://zetcode.com/db/sqlitec/

    参考:http: //zetcode.com/db/sqlitec/

    翻译自: https://www.includehelp.com/c/table-creation-data-insertion-in-sqlite-database-using-c-language.aspx

    展开全文
  • 1.创建数据库并支持中文2.在数据库中创建student3.检测的存在性4.在student表中插入数据

    1.创建数据库并支持中文

    2.在数据库中创建student表


    3.检测表的存在性


    4.在student表中插入数据


    展开全文
  • 一、Studnet: ...用到的类: DBUtil(连接、关闭数据库)、Student(学生信息)、Userdemo(接口:实现Student表的增删该查)、UserdemoImpl(实现Userdemo接口里的方法)、Test(测试台); 1、Student //S...

    一、Studnet表:

    属性:sno int(20)、cno int(4)、grade int(4)。即学号、课程号、成绩。

    二、Java中的类

    用到的类: DBUtil(连接、关闭数据库)、Student(学生信息)、Userdemo(接口:实现Student表的增删该查)、UserdemoImpl(实现Userdemo接口里的方法)、Test(测试台);

    1、Student

    //Student表
    public class Student
    {
    	private int sno;
    	private int cno;
    	private int grade;
    	
    	public Student(int sno, int cno, int grade)
    	{
    		this.sno = sno;
    		this.cno = cno;
    		this.grade = grade;
    	}
    
    	public Student()
    	{
    		
    	}
    	
    	public String toString()
    	{
    		return this.sno+","+this.cno+","+this.grade;
    	}
    
    	public int getSno()
    	{
    		return sno;
    	}
    
    	public void setSno(int sno)
    	{
    		this.sno = sno;
    	}
    
    	public int getCno()
    	{
    		return cno;
    	}
    
    	public void setCno(int cno)
    	{
    		this.cno = cno;
    	}
    
    	public int getGrade()
    	{
    		return grade;
    	}
    
    	public void setGrade(int grade)
    	{
    		this.grade = grade;
    	}
    	
    }

    2、DBUtil

    import java.io.*;
    import java.util.*;
    import java.sql.*;
    
    public class DBUtil
    {
    	
    	private static String driver = "com.mysql.cj.jdbc.Driver";   //用于加载驱动
    	private static String url = "jdbc:mysql://localhost:3306/sc3?serverTimezone=UTC";  //数据库地址
    	private static String username = "root";  //用户名
    	private static String password = "123456";   //密码
    	
    	//连接数据库
    	public static Connection open()
    	{
    		try
    		{
    			Class.forName(driver);    //加载驱动
    			return DriverManager.getConnection(url, username, password);
    		} catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    		return null;
    	}
    	
    	//关闭数据库
    	public static void close(Connection conn)
    	{
    		if(conn!=null)
    		{
    			try
    			{
    				conn.close();
    			} catch (SQLException e)
    			{
    				e.printStackTrace();
    			}
    		}
    	}
    
    }

    3、Userdemo

    import java.util.ArrayList;
    
    //实现对数据库中sc表的增、删、改、查
    public interface Userdemo
    {
    	public void Insert(Student s);
    	
    	public void Delete(int sno,int cno);
    	
    	public void Update(Student s);
    	
    	public Student Get(int sno,int cno);
    	
    	public ArrayList<Student> SelectAll();
    
    }

    4、UserdemoImpl

    import java.util.*;
    import java.sql.*;
    
    public class UserdemoImpl implements Userdemo   //实现Userdemo接口的方法
    {
    
    	@Override
    	public void Insert(Student s)   //增
    	{
    		//链接数据库
    		Connection conn = DBUtil.open();
    		//创建语句
    		String sql = "insert into sc values(?,?,?)";
    		try
    		{
    			//动态操作sql语句
    			PreparedStatement pstmt = conn.prepareStatement(sql);
    			pstmt.setInt(1,s.getSno());
    			pstmt.setInt(2,s.getCno());
    			pstmt.setInt(3,s.getGrade());
    			pstmt.executeUpdate();
    		} catch (SQLException e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			DBUtil.close(conn);  //关闭数据库
    		}
    		
    		
    		
    	}
    
    	@Override
    	public void Delete(int sno, int cno)   //删
    	{
    		Connection conn = DBUtil.open();
    		String sql = "delete from sc where sno=? and cno=?";
    		
    		try
    		{
    			PreparedStatement pstmt = conn.prepareStatement(sql);
    			pstmt.setInt(1,sno);
    			pstmt.setInt(2,cno);
    			pstmt.executeUpdate();
    		} catch (SQLException e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			DBUtil.close(conn);
    		}
    		
    		
    	}
    
    	@Override
    	public void Update(Student s)    //改
    	{
    		Connection conn = DBUtil.open();
    		String sql = "update sc set grade=? where sno=? and cno=?";
    		
    		try
    		{
    			PreparedStatement pstmt = conn.prepareStatement(sql);
    			pstmt.setInt(1,s.getGrade());
    			pstmt.setInt(2,s.getSno());
    			pstmt.setInt(3,s.getCno());
    			pstmt.executeUpdate();
    		} catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			DBUtil.close(conn);
    		}
    		
    	}
    
    	@Override
    	public Student Get(int sno, int cno)   //查
    	{
    		Connection conn = DBUtil.open();
    		String sql = "select grade from sc where sno=? and cno=?";
    		
    		try
    		{
    			PreparedStatement pstmt = conn.prepareStatement(sql);
    			pstmt.setInt(1,sno);
    			pstmt.setInt(2,cno);
    			ResultSet rs = pstmt.executeQuery();
    			if(rs.next())
    			{
    				int grade = rs.getInt(1);
    				Student s = new Student(sno,cno,grade);
    				return s;
    			}
    		} catch (Exception e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			DBUtil.close(conn);
    		}
    		
    		return null;
    	}
    
    	@Override
    	public ArrayList<Student> SelectAll()   //遍历
    	{
    		ArrayList<Student> stu = new ArrayList<Student>();
    		Connection conn = DBUtil.open();
    		String sql = "select * from sc";
    		try
    		{
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sql);
    			while(rs.next())
    			{
    				int sno = rs.getInt(1);
    				int cno = rs.getInt(2);
    				int grade = rs.getInt(3);
    				Student s = new Student(sno,cno,grade);
    				stu.add(s);
    			}
    			return stu;
    		} catch (SQLException e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			DBUtil.close(conn);
    		}
    		
    		return null;
    	}
    
    }

    5、Test

    import java.util.*;
    import java.sql.*;
    
    public class Test
    {
    	
    	public static void Create()    //创建Student表
    	{
    		Connection conn = DBUtil.open();  //连接数据库
    		String sql = "create table student(sno int(20),cno int(4),grade int(4),primary key(sno,cno))";
    		try
    		{
    			Statement stmt = conn.createStatement();  //静态操作sql语句
    			stmt.execute(sql);
    		} catch (SQLException e)
    		{
    			e.printStackTrace();
    		}
    		finally
    		{
    			DBUtil.close(conn);
    		}
    	}
    	
    	public static void show()  //提示信息
    	{
    		System.out.println("***********成绩数据库管理***********");
    		System.out.println("insert: 插入成绩.");
    		System.out.println("delete: 删除成绩.");
    		System.out.println("update: 更新成绩.");
    		System.out.println("get: 查看成绩.");
    		System.out.println("list: 查看所有成绩.");
    		System.out.println("***********成绩数据库管理***********");
    	}
    
    	public static void main(String[] args)
    	{
    		Scanner in = new Scanner(System.in);
    //		Create();
    		Userdemo userdemo = new UserdemoImpl();   //多态
    		Student stu = new Student();
    		while(true)
    		{
    			show();
    			System.out.print("命令>");
    			String s = in.next();
    			if(s.equals("insert"))
    			{
    				System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");
    				System.out.print("请输入学号:");
    				int sno = in.nextInt();
    				System.out.print("请输入课程号:");
    				int cno = in.nextInt();
    				System.out.print("请输入成绩:");
    				int grade = in.nextInt();
    				stu.setSno(sno);
    				stu.setCno(cno);
    				stu.setGrade(grade);
    				userdemo.Insert(stu);
    			}
    			else if(s.equals("delete"))
    			{
    				System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");
    				System.out.print("请输入待删除的学号:");
    				int sno = in.nextInt();
    				System.out.print("请输入待删除的课程号:");
    				int cno = in.nextInt();
    				userdemo.Delete(sno, cno);
    			}
    			else if(s.equals("update"))
    			{
    				System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");
    				System.out.print("请输入待更新的学号:");
    				int sno = in.nextInt();
    				System.out.print("请输入待更新的课程号:");
    				int cno = in.nextInt();
    				System.out.print("请输入新成绩:");
    				int grade = in.nextInt();
    				stu.setSno(sno);
    				stu.setCno(cno);
    				stu.setGrade(grade);
    				userdemo.Update(stu);
    			}
    			else if(s.equals("get"))
    			{
    				System.out.println("请输入正确的信息,如果重复、不存在、信息错误,都会出现错误.");
    				System.out.print("请输入查询的学号:");
    				int sno = in.nextInt();
    				System.out.print("请输入查询的课程号:");
    				int cno = in.nextInt();
    				stu = userdemo.Get(sno, cno);
    				System.out.println("成绩:"+stu.getGrade());
    			}
    			else if(s.equals("list"))
    			{
    				ArrayList<Student> note = userdemo.SelectAll();
    				for(int i=0,t=note.size();i<t;i++)
    				{
    					System.out.println(note.get(i));
    				}
    				
    			}
    			else if(s.equals("exit"))
    			{
    				System.out.println("再见!");
    				System.exit(0);
    			}
    		}
    
    	}
    
    }
    

     

    展开全文
  • Oracle数据库中创建表

    千次阅读 2016-10-02 22:28:29
    固定格式其中,约束分为列级约束(因为是跟列的声明后面写的)和级约束(因为是全部列声明完之后写的),列级约束和级约束都是对列的值进行约束的,例如:列的值不能为空,列的值必须是唯一的等等 注:列级约束也...
  • mydb数据库中创建student数据中有id、name(学生姓名)、math(数学成绩)、chinese(语文成绩)和english(英语成绩)字段。然后创建视图view_score,视图中包含math、chinese、english和total(总分数)...
  • MySQL数据库中创建课程管理网站需要的数据库(couman)和相关。 完整标题: 管理员准备MySQL数据库中创建课程管理网站需要的数据库(couman)和相关。数据包括学生信息(student)、课程描述(course)、学生...
  • 【单选题】汽车直线行驶过程,要求汽车车轮沿行驶方向做 运动。 (3.1分)【单选题】手动变速器自锁装置失效,将导致变速器()【单选题】5. 手动变速器车型,当离合器从动盘磨损变薄后,离合器踏板自由行程( )...
  • 1. 数据插入功能。能增加班级;给某班增加学生2....能修改班级名称看到这个题目以后,不要认为有多难,根据题目所要求的一步一步的来,第一步,先在数据库中创建两张,并添加数据SQL: create table stu...
  • 练习1:在student数据库中创建student和grade。student结构如下字段名字段描述数据类型主键外键非空唯一自增no 学号int 是否是是否name 姓名varchar(30) 否否是否否sex 性别char(2) 否否是否否birthday 出生...
  • 1.启动mysql服务 service mysqld start(注意!!要先切换到root用户) (ps:我书上看的是service mysql start,但是提示了这样的信息,这是错的 ...(ps:创建一个student表 4.查看数据库show databases;...
  • 1,创建Student数据库,包括Students,Courses,SC结构如下: Students(SNO,SNAME,SEX,BDATE,HEIGHT,DEPARTMENT) Courses(CNO,CNAME,LHOUR,CREDIT,SEMESTER) SC(SNO,CNO,GRADE) (注:下划线表示主键,斜体表示...
  • 今天我们就以实验的形式对表的创建、管理和数据操作进行学习,上课吧。【实验目的】:了解SQL语言的使用,进一步理解... 利用数据定义语句实验一创建的stu_DB库建立学生管理系统的三个Student、Course、SC。...
  • 数据库与数据表创建

    2019-04-20 08:37:02
    实验步骤: 1.创建教学管理“JXGL”数据库。(注:可采用可视窗体和SQL命令两种方法创建。...(2) 清空命令窗格后,JXGL数据库中建立STUDENT表,并插入记录,然后执行。 CREATE TABLE STUDENT (S...
  • 在数据库db_stu中创建一张学生,表名:student,且包括以下列:stuno(学号),name(姓名),sex(性别),Birthday(出生日期),并且设置学号stuno为主键,name(姓名)列不能为空,且stuno为自增...
  • 创建表Student Create Table Student( id number(12) primary key, --通过序列和触发器实现id的自增 name varchar2(20) , age number(3) , sex number(1) ) 创建序列Sequence Create Sequence SEQ_STUDENT ...
  • 必须先开启服务,开启服务使用 mongod --dbpathc:\mongodb管理 mongodb 数据库:mongo (一定要新的 cmd 输入)清屏:cls查看所有数据库列表show dbs二、 创建数据库使用数据库创建数据库use student如果真的想...
  • 数据库使用开启 mongodb 服务:要管理数据库,必须先开启服务,开启服务使用 mongod --dbpath D:\mongodb 管理 mongodb 数据库:mongo (一定要新的 cmd 中输入) 清屏:cls查看所有数据库列表...数据库中不能直
  • 1.自己创建的用户方案下用sql语句创建表student,存放users表空间,用sql语句添加如下记录;   01  要求的约束条件有: 02  主键是学号;入学日期必须大于出生日期;...
  • 数据库表创建

    2021-02-01 15:31:43
    数据库表 --设计要求:建立一张用来存储学生信息的表中的字段包含了学生的学号、姓名、年龄、入学日期、年级、班级、email等信息 --并且为grade指定了默认值为1,如果插入数据时不指定grade的值,就代表是...
  • Hibernate: insert into Student (age, name, id) values (?, ?, ?) Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate....
  • create database hive_db //创建数据库hive_dbcreate table hive_db.test(字段内容及其格式省略) //在数据库hive_db中创建testcreate database student_db location '/user/hive/student.db' //创建数据库...
  • <p>I am using xampp for my database and I wanted to make a database with "students" table, only one column for the list of student IDs, and every student ID has another table inside. (I was ...
  • 设计数据库表的时候发现Oracle没有自增主键的设置,Google了解到...创建表StudentCreate Table Student(id number(12) primary key, --通过序列和触发器实现id的自增name varchar2(20) ,age number(3) ,sex n...
  • hive的数据定义之创建数据库

    千次阅读 2019-06-26 22:08:00
    1、对数据库的操作 ... create table hive_db.test(字段) //在数据库hive_db中创建test    create database student_db location '/user/hive/student.db' //创建数据库student_db,但是hd...
  • 简述之前都是宿舍的一个台式电脑上写数据库的作业,...环境介绍windows 10mysql 8.0 +Command Line Client 操作代码以及对应的解释创建student表在性别上,设置了只能选 男或者是女mysql> create table studen...
  • 62616964757a686964616fe78988e69d83313334313766301、首先我们使用数据库连接工具HeiDiSQL来连接本机的mysql数据库,2、使用该工具创建一个test数据库,3、数据库中创建一张student表,该中有id、name和age...
  • [school_id,student_id,marks] e.exams. [school_id,class_id,exam_id,exam_name] </code></pre> <p>Now for a particular school's , let's say 'ABC school' which has school_id = 10 . </p> <pre><code>I ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 949
精华内容 379
关键字:

在student数据库中创建表