When I connect to an Access database (.mdb) which is encoded with ISO-8859-1 I
use this syntax:
String dbPath = "fakeDBPath.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + dbPath + ";DriverID=22;READONLY=false}";
final Properties prop = new Properties();
prop.put("charSet", "ISO-8859-1");
Connection conn = DriverManager.getConnection( database, prop );
After I get the Connection I'm able to use Java strings withouth the need to specify any additional encoding.
Maybe JTDS supports a specific propertiy to set encoding.
For example, to insert data in the DB:
String cmd = "INSERT INTO Table (Col1,Col2,Col3,Col4) VALUES (1000,'àèìòù','é®þü','fake data');";
Statement s = DBTable_1.getStatement();
try
{
int r = s.executeUpdate(cmd);
} catch ( SQLException ex )
{
Logger.getLogger( Main.class.getName() ).log( Level.SEVERE, null, ex );
}
And to read from the DB:
String cmd = "SELECT * FROM Table WHERE Col2='àèìòù';";
Statement s = DBTable_1.getStatement();
try
{
ResultSet r = s.executeQuery(cmd);
while(r.next())
{
System.out.println("Col2: " + r.getString(2) + " Col3:" + r.getString(3));
}
} catch ( SQLException ex )
{
Logger.getLogger( Main.class.getName() ).log( Level.SEVERE, null, ex );
}