title: Save and Load UTF-8 From Oracle 10g with iBatis
body: <p>I'm making a web app that needs to load and save UTF-8 (Korean, specifically) characters from a DB.  I've been given an account on the Oracle 10g server, but it saves <code>VARCHAR2</code> type columns as <code>ASCII7</code>, with each UTF-8 character taking 2 <code>VARCHAR2</code> slots.</p>
  
  <p>I assumed that since iBatis is writing in the same way that it is reading, if I treat everything from input to output as UTF-8 I will have no problems, but any Korean characters I input come out garbled.</p>
  
  <p>Is there a way to do this properly without messing up the (someone else's) DB?</p>
  
  <p>Further information:</p>
  
  <p>I've previously been able to load Korean strings using:</p>
  
  <pre><code>ResultSet rs = ps.executeQuery();
  String koreanString = new String(rs.getBytes("colname"), "euc-kr");
  </code></pre>
  
  <p>And write Korean strings to db using:</p>
  
  <pre><code>PreparedStatement ps = conn.prepareStatement(sql);
  ps.setString(1, new String(koreanString.getBytes("euc-kr"), "ISO-8859-1"));
  </code></pre>
  
  <p>Attempts to change the JDBC connection url result in this message:</p>
  
  <p>Description</p>
  
  <pre><code>Listener refused the connection with the following error:
  ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  The Connection descriptor used by the client was:
  [ip]:myTablespace?useUnicode=true&amp;characterEncoding=UTF-8
  </code></pre>
  
  <p>error dump   </p>
  
  <pre><code>javax.servlet.ServletException: Listener refused the connection with the following error:
  ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  The Connection descriptor used by the client was:
  [ip]:myTablespace?useUnicode=true&amp;characterEncoding=UTF-8
  
  at jeus.servlet.jsp2.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:859)
  at jeus.servlet.jsp2.runtime.PageContextImpl.handlePageException(PageContextImpl.java:789)
  at jeus_jspwork._jsp._500_managerAdmin_5fjsp._jspService(_500_managerAdmin_5fjsp.java:452)
  at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:95)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:147)
  at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:365)
  at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:284)
  </code></pre>
  
  <p>root cause</p>
  
  <pre><code>java.sql.SQLException: Listener refused the connection with the following error:
  ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
  The Connection descriptor used by the client was:
  [ip]:myTablespace?useUnicode=true&amp;characterEncoding=UTF-8
  
  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
  at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
  at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
  at oracle.jdbc.driver.PhysicalConnection.&lt;init&gt;(PhysicalConnection.java:441)
  at oracle.jdbc.driver.T4CConnection.&lt;init&gt;(T4CConnection.java:165)
  at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
  at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
  at java.sql.DriverManager.getConnection(DriverManager.java:525)
  at java.sql.DriverManager.getConnection(DriverManager.java:171)
  at com.ibatis.common.jdbc.SimpleDataSource.popConnection(SimpleDataSource.java:580)
  at com.ibatis.common.jdbc.SimpleDataSource.getConnection(SimpleDataSource.java:222)
  at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.init(JdbcTransaction.java:48)
  at com.ibatis.sqlmap.engine.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:89)
  at com.ibatis.sqlmap.engine.mapping.statement.MappedStatement.executeQueryForObject(MappedStatement.java:120)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:518)
  at com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate.queryForObject(SqlMapExecutorDelegate.java:493)
  at com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl.queryForObject(SqlMapSessionImpl.java:106)
  at com.ibatis.sqlmap.engine.impl.SqlMapClientImpl.queryForObject(SqlMapClientImpl.java:82)
  at [].admRole.getCount(admRole.java:44)
  at jeus_jspwork._jsp._500_managerAdmin_5fjsp._jspService(_500_managerAdmin_5fjsp.java:145)
  at jeus.servlet.jsp2.runtime.HttpJspBase.service(HttpJspBase.java:95)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  at jeus.servlet.jsp.JspServletWrapper.executeServlet(JspServletWrapper.java:147)
  at jeus.servlet.servlets.JspServlet.execute(JspServlet.java:365)
  at jeus.servlet.engine.HttpRequestProcessor.run(HttpRequestProcessor.java:284)
  </code></pre>