view src/main/java/org/mpi/openmind/scripts/ChangeEntityPrivacity.java @ 8:478fd6f26ea8

(none)
author jurzua
date Tue, 24 Feb 2015 10:45:45 +0000
parents 615d27dce9b3
children
line wrap: on
line source

package org.mpi.openmind.scripts;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import org.apache.commons.lang.StringUtils;

public class ChangeEntityPrivacity {

	public static void execute(boolean privacity) {
		try {
		
			Connection conn;

			Class.forName("com.mysql.jdbc.Driver").newInstance();
			String url = "jdbc:mysql://localhost/openmind?characterEncoding=UTF-8";
			conn = DriverManager.getConnection(url, "ismi", "ismipw");
			
			
			Statement st = conn.createStatement();
			//((privacity)? "1" : "0") 
			String sql = "UPDATE node SET public =" + privacity + "";
			System.out.println("Executing:");
			System.out.println(sql);
			int n = st.executeUpdate(sql);
			//System.out.println(n + " rows were modified");
			
			conn.close();
		
		} catch (ClassNotFoundException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		} catch (IllegalAccessException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		} catch (InstantiationException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		} catch (SQLException ex) {
			System.err.println(ex.getMessage());
			ex.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		String arg = args[0];
		System.out.println("arg: " + arg);
		boolean privacity = false;
		if(StringUtils.isNotEmpty(arg)){
			try{
				privacity = new Boolean(arg);
			}catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		ChangeEntityPrivacity.execute(privacity);
		System.exit(0);
	}
	
}