Uploaded by atm officialszw

assaignment java 1

advertisement
package com.BugaMcvellie;
import java.sql.*;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
try {
System.out.println("Enter username:");
String username =s.next();
System.out.println("Enter password:");
String password =s.next();
System.out.println("Enter your name:");
String name =s.next();
System.out.println("Enter surname:");
String surname = s.next();
System.out.println("Enter reg number:");
String regnumber = s.next();
System.out.println("Enter module:");
String module =s.next();
System.out.println("Enter gender:");
String gender =s.next();
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/crud", "tendai",
"buga1234");
PreparedStatement pst = con.prepareStatement("insert into
data(username,password,name,surname,reg number,module,gender)
values(?,?,?,?,?,?,?)");
pst.setString(1,username);
pst.setString(2, password);
pst.setString(3, name);
pst.setString(4,surname );
pst.setString(5, regnumber);
pst.setString(6, module);
pst.setString(7, gender);
int i = pst.executeUpdate();
if(i!=0){
System.out.println("added");
}
else{
System.out.println("failed to add");
}
}
catch (Exception e){
System.out.println(e);
}
}
}
STUDENTS
-Id int
+Reg number int
+Student Name str
chooses
1..*
COURSE
+Course code : int
+Program str
+course name: str
+student type str
Register course():str
Getcoursecode():int
Unregister():str
Register(string string string):boolean
Get regnumber():int
List_all_student():str
Edit student (id)int
Registration
Student regnumber():int
Student name():str
Number of courses():int
Course registered():str
Register student():str
Register course():str
Unregister():str
Download