}
Modify
public void Update ()
{
Con=getdbconnect ();
sql= "Update student set Stuname= ' Ben ' where stuno= ' 2 '";
try {
Stat=con.createstatement ();
catch (SQLException e) {
E.printstacktrace ();
}
}
Inquire
public void Search () {
con = Getdbconnect ();
To create a table's SQL statement
sql = "SELECT * from student";
try {
Stat = Con.createstatement ();
rs= stat.executequery (SQL);
while (Rs.next ()) {
String Stuno = rs.getstring (1);
String stuname = rs.getstring (2);
String stusex = rs.getstring (3);
System.out.println (Stuno + "," + Stuname + "," + stusex);
}
catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
Function: Close the connection to the database
public void Close () {//6. Releasing resources
try {//catch exception
try {
if (rs!= null) {//When the instance Rs of the ResultSet object is not empty
Rs.close (); Close ResultSet Object
}
finally {
try {
if (stat!= null) {//When an instance of the statement object stmt is not empty
Stat.close (); Close Statement Object
}
finally {
if (con!= null) {//When an instance of the Connection object conn is not empty
Con.close (); Close Connection Object
}
}
}
catch (Exception e) {
E.printstacktrace (System.err); Output exception information
}
}
public static void Main (string[] args) {
Conoracl oracl = new Conoracl ();
System.out.println (before "Operation:");
Oracl. Search ();
Oracl. ADD ();
Oracl. Delete ();
Oracl. Update ();
System.out.println ("After Operation:");
Oracl. Search ();
Oracl.close ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.