Java: MonitoraChar - Corrigindo caracteres estranhos em um banco de dados com java
package monitoracaracteres;
/*
Abrir o arquivo em um editor Notepad++ para que os caractes estranhos sejam apresentados
select count(1) as CONT from WIKIS.MEDIA where LABEL like '%�%'"
update WIKIS.MEDIA SET TITLE=REPLACE(TITLE,' ','') where TITLE like '% %
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
/**
*
* @author ebasso
*/
public class MonitoraChar {
private static String sourceDbUserid = "<username>";
private static String sourceDbPassword = "<password>";
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
MonitoraChar myApp = new MonitoraChar();
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
System.out.println("\nCodePointAt => " + "�".codePointAt(0) + "\n");
int a = '�';
System.out.println("\n a => " + a + "\n");
System.out.println("\nIniciando Checagem\n\n");
System.out.println("\n");
myApp.CheckActivitiesDB();
} catch (Exception e) {
e.printStackTrace();
}
}
private void CheckActivitiesDB() throws Exception {
String sourceDbUrl = "jdbc:db2://192.168.1.1:50000/OPNACT:retrieveMessagesFromServerOnGetMessage=true;";
int count = 0;
Connection sourceCon = DriverManager.getConnection(sourceDbUrl, sourceDbUserid, sourceDbPassword);
Statement stmt = sourceCon.createStatement();
System.out.println("\nVerificando tabela ACTIVITIES.OA_NODE coluna NAME");
ResultSet rs = stmt.executeQuery("select count(1) as CONT from ACTIVITIES.OA_NODE where NAME like '%�%'");
count = 0;
while (rs.next()) {
count = rs.getInt("CONT");
}
if (count == 0) {
System.out.println(" count => 0 - OK");
} else {
System.out.println(" count => " + count + " - ERROR = Tabela necessita correcoes");
}
sourceCon.close();
}
}
Ver também