Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mysqlconn;
- import java.sql.*;
- import java.util.*;
- public class Mysqlconn {
- public static void main(String[] args)throws SQLException {
- try {
- String url="jdbc:mysql://localhost:3306/newdatabase";
- Properties prop=new Properties();
- prop.setProperty("user","root");
- prop.setProperty("password","");
- Driver d = new com.mysql.jdbc.Driver();
- Connection con = d.connect(url,prop);
- if(con == null) {
- System.out.println("connection failed");
- return;
- }
- // these are variables to insert
- String fname = "Tarek";
- String query1 = "DELETE FROM user WHERE first_name = 'Sifat';
- String query2 = "DELETE FROM user WHERE first_name = '" + fname + "'";
- Statement state = con.createStatement();
- ResultSet result = null;
- state.executeUpdate(query1);
- state.executeUpdate(query2);
- state.close();
- } catch (Exception e)
- {
- System.err.println("Got an exception!");
- System.err.println(e.getMessage());
- }
- }
- }
Add Comment
Please, Sign In to add comment