Adding and pruning database operations

Source: Internet
Author: User
Tags sql server driver

This article connects to the SQL Server driver for the JDBC driver link that was used in the previous chapter

Package addressutil;


Import java.sql.Connection;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.sql.Statement;


Import javax.swing.text.DefaultEditorKit.InsertBreakAction;


Import Bookconnutil.dbutil;


public class Addressutil {
Private address address = new address ();
public static Boolean addressupdate (String name,string email,string phone,string company,string address) throws sqlexception{
String updatewithname = "Update address set email=?,phone=?,company=?,address=?where name=?";

Boolean flag =false;

Connection Conn=null;
PreparedStatement Stmt=null;
ResultSet Rs=null;
try{
Conn=dbutil.getconnection (Dbutil.connection_sql);
Stmt=conn.preparestatement (Updatewithname);
int count=stmt.executeupdate ();
Stmt.setstring (1, email);
Stmt.setstring (2, phone);
Stmt.setstring (3, company);
Stmt.setstring (4, address);
Stmt.setstring (5, name);
if (count>0) {
Flag=true;
}else {
Flag=false;
}

}catch (Exception e) {
E.printstacktrace ();

//Do not have specific exception handling for it just a simple capture if you need to modify it yourself
}finally{
Conn.close ();
Stmt.close ();

}
return flag;
}
public static Boolean Addressselect (String name) throws sqlexception{
String selectaddress = "Select Email,phone,company,address,from address where name=?";

Boolean flag =false;

Connection Conn=null;
PreparedStatement Stmt=null;
ResultSet Rs=null;
try{
Conn=dbutil.getconnection (Dbutil.connection_sql);
Stmt=conn.preparestatement (selectaddress);
int count=stmt.executeupdate ();
Stmt.setstring (1, name);

if (count>0) {
Flag=true;
}else {
Flag=false;
}

}catch (Exception e) {
E.printstacktrace ();

There is no specific exception handling, just a simple capture if you need to modify it yourself
}finally{
Conn.close ();
Stmt.close ();

}
return flag;

}
public static Boolean Addressdelete (String name) throws sqlexception{
String deleteaddress = "Delete * from address where name=?";

Boolean flag =false;

Connection Conn=null;
PreparedStatement Stmt=null;
ResultSet Rs=null;
try{
Conn=dbutil.getconnection (Dbutil.connection_sql);
Stmt=conn.preparestatement (deleteaddress);
int count=stmt.executeupdate ();
Stmt.setstring (1, name);

if (count>0) {
Flag=true;
}else {
Flag=false;
}

}catch (Exception e) {
E.printstacktrace ();

//Do not have specific exception handling for it just a simple capture if you need to modify it yourself
}finally{
Conn.close ();
Stmt.close ();

}
return flag;

}
public static Boolean Addressinsert (String name,string email,string phone,string company,string address) throws sqlexception{
Boolean flag =false;
Try
{
Connection Con=null;
Con=dbutil.getconnection (1);
String insert= "Insert into address values (?,?,?,?,?)";
PreparedStatement stmt = null;
stmt =con.preparestatement (Insert);

Stmt.setstring (1, name);
Stmt.setstring (2, email);
Stmt.setstring (3, phone);
Stmt.setstring (4, company);
Stmt.setstring (5, address);



System.out.println ("??????");
int count=stmt.executeupdate ();
System.out.println ("11111111111111111111111111111");



if (count>0)
{
Flag = true;

}else{
Flag=false;

}


} catch (Exception e) {
E.printstacktrace ();
System.out.println ("gone awry");
}
return flag;
}

}

Adding and pruning database operations

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.