- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
public static void setSQLSafeFormat(JFormattedTextField ftf){
DefaultFormatter sqlSafeFormatter = new DefaultFormatter(){
@Override
public Object stringToValue(String string) throws ParseException {
string = string.replaceAll("\'", "");
return super.stringToValue(string);
}
@Override
public String valueToString(Object value) throws ParseException {
String result = super.valueToString(value);
return result.replaceFirst("\'", "");
}
};
sqlSafeFormatter.setOverwriteMode(false);
ftf.setFormatterFactory(new DefaultFormatterFactory(sqlSafeFormatter));
}
public static void setSQLSafeFilter(JTextField txt){
DocumentFilter dc = new DocumentFilter(){
@Override
public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException {
if(!string.contains("'"))
super.insertString(fb, offset, string, attr);
}
@Override
public void replace(FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
if(!text.contains("'"))
super.replace(fb, offset, length, text, attrs);
}
};
AbstractDocument asb = (AbstractDocument)txt.getDocument();
asb.setDocumentFilter(dc);
}
Lure Of Chaos 09.08.2010 20:27 # 0
Анонимус 10.08.2010 12:53 # 0