MySQL Blur delete

Source: Internet
Author: User

You can blur the search first, put it in the container, delete

Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.util.ArrayList;
Import java.util.List;

public class Newsdbo {
PRIVATE Connection conn = null;
PreparedStatement statement = null;

Connect to MySQL
public void Connsql () {
String Urle = "jdbc:mysql://192.168.1.100:3306/state?useunicode=true&characterencoding=utf-8";//port:3306
Database:testdb
String username = "root";//user
String password = "";//Password

try {
try {
Class.forName ("Com.mysql.jdbc.Driver"). newinstance ();
} catch (Instantiationexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}//load driver, connect to database
conn = Drivermanager.getconnection (Urle, username, password);
}
Capturing Load Driver exceptions
catch (ClassNotFoundException Cnfex) {
SYSTEM.ERR.PRINTLN ("Load Jdbc/odbc driver failed. ");
Cnfex.printstacktrace ();
}
Catching Connection Database Exceptions
catch (SQLException Sqlex) {
System.err.println ("Unable to connect to database");
Sqlex.printstacktrace ();
}
}

Disconnect to MySQL
public void Deconnsql () {
try {
IF (conn! = null)
Conn.close ();
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("Close database Problem:");
E.printstacktrace ();
}
}

Execute selection language
Public ResultSet selectsql (String sql) {
ResultSet rs = null;
try {
statement = conn.preparestatement (SQL);
rs = statement.executequery (SQL);
} catch (SQLException e) {
E.printstacktrace ();
}
Return RS;
}

Execute insertion language
public boolean insertsql (String sql) {
try {
statement = conn.preparestatement (SQL);
Statement.executeupdate ();
return true;
} catch (SQLException e) {
SYSTEM.OUT.PRINTLN ("Error inserting database:");
E.printstacktrace ();
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("error when inserting:");
E.printstacktrace ();
}
return false;
}

public boolean insert (String sql, object[] params) {
if (SQL! = null &&!sql.equals ("")) {
PreparedStatement pstm = null;
if (params = = null)
params = new Object[0];
IF (conn! = null) {
try {
Pstm = (preparedstatement) conn.preparestatement (SQL,
Resultset.type_scroll_insensitive,
RESULTSET.CONCUR_READ_ONLY);
for (int i = 0; i < params.length; i++) {
Pstm.setobject (i + 1, params[i]);
}
Pstm.execute ();
return true;
} catch (SQLException e) {
throw new RuntimeException (e);
}
}
}
return false;
}

Execute Delete language
public boolean deletesql (String sql) {
try {
statement = conn.preparestatement (SQL);
Statement.executeupdate ();
return true;
} catch (SQLException e) {
SYSTEM.OUT.PRINTLN ("Error inserting database:");
E.printstacktrace ();
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("error when inserting:");
E.printstacktrace ();
}
return false;
}

Execute Update language
public boolean updatesql (String sql) {
try {
statement = conn.preparestatement (SQL);
Statement.executeupdate ();
return true;
} catch (SQLException e) {
SYSTEM.OUT.PRINTLN ("Error inserting database:");
E.printstacktrace ();
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("error when inserting:");
E.printstacktrace ();
}
return false;
}

Show data in Ju_users
Public list<string> LayoutStyle2 (ResultSet rs) {
list<string> topics = new arraylist<string> ();
String desc;

try {
while (Rs.next ()) {
desc = new String ();
System.out.println (rs.getstring (1));
desc = rs.getstring (1);

Topics.add (DESC);
}
} catch (SQLException e) {
SYSTEM.OUT.PRINTLN ("A database error occurred while displaying. ");
E.printstacktrace ();
} catch (Exception e) {
SYSTEM.OUT.PRINTLN ("Display error. ");
E.printstacktrace ();
}
return topics;
}

public static void Main (String args[]) {
System.out.println ("SFS");
list<string> descid = new arraylist<string> ();
Newsdbo newsdbo = new newsdbo ();
Newsdbo.connsql ();
String select = "Select *from Recorder where descid like '%kaidi% '";
Descid = Newsdbo.layoutstyle2 (Newsdbo.selectsql (select));
String Delete = "Delete from recorder";
Newsdbo.deletesql (delete);
for (int i = 0; i < descid.size (); ++i) {
String Delete = "Delete from recorder where descid= '"
+ Descid.get (i) + "'";
Newsdbo.deletesql (delete);
}
Newsdbo.deconnsql ();
}
}

MySQL blur removal

Related Article

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.