Home > Back-end >  Rookie great god grant instruction
Rookie great god grant instruction

Time:09-22

The function of the following procedure is to the database using JDBC JavaTest student table inserted in a record, and query the content of the student table and put all the records in the table output, according to the comments by filling in the blanks on the appropriate statement, make the program to realize the corresponding function,
Note: the student table, a total of three columns, id, name, sex types respectively: int, varchar (10), a varchar (2)
Public class JDBCTest {
Public static void main (String [] args) {
Connection conn=null;
PreparedStatement PST=null;
The Statement STM=null;
ResultSet rs=null;
Try {class.forname (" com. Microsoft. Essentially. JDBC. SQLServerDriver ");
Conn=DriverManager. GetConnection (" JDBC: essentially://127.0.0.1:1433; Databasename=JavaTest ", "sa", "123");
String SQL="insert into student (id, name, sex) values (?,?,?,?,? ,? ,?) ";
PST=conn. PrepareStatement (SQL);
PST. SetInt (1, 1);
//sets the name to "zhang"
_____________________________________________
PST. SetString (3, "male");
PST. ExecuteUpdate ();
PST. The close ();
String query="select id, name, sex from student";
STM=conn. CreateStatement ();
Rs=STM. ExecuteQuery (query);
//the cursor move forward from the current position of a line, and whether the next row record
While (____________________)
{
Int id=rs. Get int (" id ");
String name=rs. Get String (" name ");
String sex=rs. Get String (" sex ");
System. The out. Println (id + "" + name +" "+ sex);
}
rs.close();
STM. The close ();
conn.close();
} the catch (a ClassNotFoundException e) {
e.printStackTrace();
} the catch (SQLException e) {
e.printStackTrace();
}
}
}

The problem is how to do?

CodePudding user response:

To control their own code to fill in https://blog.csdn.net/weixin_43982698/article/details/90317580? Utm_source=app

CodePudding user response:

PST. SetString (2, "zhang");
Rs. Next ()
  • Related