Second, increase
public static void Main (string[] args) {
TODO auto-generated Method Stub
4. User input items that need to be added
Scanner sc = new Scanner (system.in);
System.out.println ("Please enter the data you want to add:");
System.out.println ("2. Name");
String a = Sc.nextline ();
System.out.println ("3. Gender");
String three = Sc.nextline ();
System.out.println ("4. Age");
int fore= integer.parseint (Sc.nextline ());
System.out.println ("5. School Code");
int five= integer.parseint (Sc.nextline ());
try {
1. Import the database and link
Class.forName ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = drivermanager.getconnection ("Jdbc:sqlserver://192.168.8.60;databasename=school", "sa", "123456");
3. Write SQL statements
String sql= "INSERT into [Student] values (? ,? ,? ,? )";
2. Remove the database content and show it in SQL form
PreparedStatement stmt= conn.preparestatement (SQL);
Stmt.setobject (1,two);
Stmt.setobject (2,three);
Stmt.setobject (3,fore);
Stmt.setobject (4,five);
5. Decide whether to add success
if (!stmt.execute ()) {
SYSTEM.OUT.PRINTLN ("Data added successfully");
}else{
SYSTEM.OUT.PRINTLN ("Data addition not successful");
}
6. Close the data
if (!stmt.isclosed ()) {stmt.close (); } if (!conn.isclosed ()) {conn.close (); }
} catch (ClassNotFoundException E1) {//TODO auto-generated catch block E1.printstacktrace (); }catch (SQLException e) {//TODO auto-generated catch block E.printstacktrace (); } }
Working with my Exclipse database (2)