Archive

Archive for the ‘JDBC’ Category

ORA-12505: TNS:listener does not currently know of SID given in connect descriptor

9 December 2010 25 comments

I am not sure why I get this error since I can connect to the current SID by using sqlplus but I cannot connect to it by using jdbc with the following url:

jdbc:oracle:thin:@aHost:1521:theSID

After searching for about an hour I found out that you can also use the full blown jdbc url protocol to connect to oracle

jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=aHost) (PORT=1521))(CONNECT_DATA=(SERVICE_NAME=theSID)))

This does not explain why the issue happens but at least for now it solves the problem. I will post an update if I find anything else.

Advertisements
Categories: JDBC, Oracle

java.sql.SQLException: Incorrect string value: ‘\xCF\x82 \xCE\xBC\xCE…’ for column ‘body’ at row 1

17 March 2010 8 comments

If you are getting this while trying to insert some unicode characters in a text type column in the database it will probably go away if you change the type of the column to longtext. I was getting it with the following table

CREATE TABLE messages (
  id int(10) unsigned NOT NULL,
  body text,
  PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

and Java code

Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/simpledb?useUnicode=true&characterEncoding=utf8", "username", "password"
Statement insertSt = conn.createStatement();
insertSt.executeUpdate("INSERT INTO messages (id, body) VALUES (" + id + ", '" + body + "')");
insertSt.close();

and the following exception

java.sql.SQLException: Incorrect string value: '\xCF\x82 \xCE\xBC\xCE...' for column 'body' at row 1
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3562)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3494)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1960)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2690)
        at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1648)
        at com.mysql.jdbc.StatementImpl.executeUpdate(StatementImpl.java:1567)
        at migration.JDBCConnection.main(JDBCConnection.java:78)

The solution was to simply change the data type of body to longtext

CREATE TABLE messages (
  id int(10) unsigned NOT NULL,
  body longtext,
  PRIMARY KEY (id)
) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
Categories: Java, JDBC Tags: