Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VV2Or-000320-SL for pgsql-jdbc@arkaria.postgresql.org; Sat, 12 Oct 2013 16:50:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VV2Oq-0006eK-7E for pgsql-jdbc@arkaria.postgresql.org; Sat, 12 Oct 2013 16:50:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VV2Oo-0006eB-8l for pgsql-jdbc@postgresql.org; Sat, 12 Oct 2013 16:50:42 +0000 Received: from outbound.vnet-inc.com ([216.146.104.103]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VV2Of-0007zY-Ad for pgsql-jdbc@postgresql.org; Sat, 12 Oct 2013 16:50:40 +0000 Received: from [192.168.157.132] (unknown [65.19.243.151]) by outbound.vnet-inc.com (Postfix) with ESMTP id 8A52A7AB7 for ; Sat, 12 Oct 2013 10:50:03 -0600 (MDT) Message-ID: <52597C74.6070104@ttc-cmc.net> Date: Sat, 12 Oct 2013 10:44:36 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.13) Gecko/20100914 SeaMonkey/2.0.8 MIME-Version: 1.0 To: PostgreSQL JDBC Subject: Re: Java String saving as unicode in database References: <1381565943021-5774370.post@n5.nabble.com> In-Reply-To: <1381565943021-5774370.post@n5.nabble.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Hello, Example: private void testInsertUTF(Connection con) { // Method Instances String sqlStatementString; Statement sqlStatement; PreparedStatement pstmt; ResultSet rs; try { // Setup a connection statement. sqlStatement = con.createStatement(); // Create table. sqlStatementString = "DROP TABLE IF EXISTS jdbc_demo"; System.out.println(sqlStatementString); sqlStatement.execute(sqlStatementString); sqlStatementString = "Create Table jdbc_demo (col VARCHAR(30))"; System.out.println(sqlStatementString); sqlStatement.execute(sqlStatementString); // Insert data. System.out.println("Inserting Data"); pstmt = con.prepareStatement("INSERT INTO jdbc_demo VALUES (?)"); pstmt.setString(1, "*Sample\u0020\u0061\u0074\u0020\u0032\u0032\u0042\u0020 text*"); pstmt.execute(); // View data. sqlStatementString = "SELECT * FROM jdbc_demo"; System.out.println(sqlStatementString); sqlStatement.execute(sqlStatementString); rs = sqlStatement.executeQuery(sqlStatementString); JPanel panel = new JPanel(); while (rs.next()) { String dataString = rs.getString("col"); System.out.println("col:" + dataString); panel.add(new JLabel(dataString)); } rs.close(); JFrame frame = new JFrame(); frame.getContentPane().add(panel); frame.setSize(200, 200); frame.setVisible(true); // Clean up. sqlStatementString = "DROP TABLE IF EXISTS jdbc_demo"; System.out.println(sqlStatementString); sqlStatement.execute(sqlStatementString); sqlStatement.close(); pstmt.close(); } catch (SQLException sqle) { System.out.println("SQL Exeception" + sqle); } } saisantoshi wrote: > Hi, > > I want to store java string as a unicode string in the database. Please let > me know if this is possible? > > For example : > > String columnValue="*Sample > \u0020\u0061\u0074\u0020\u0032\u0032\u0042\u0020 text*"; > > I want to save the above exactly (as it is which is bolded) into the > database and retreive it. > > DB column should store as : > > ColumnA > --------- > Sample \u0020\u0061\u0074\u0020\u0032\u0032\u0042\u0020 text ( with > unicode string value) > > > When read it back from java, it should display: > Sample at 22B text > > -- > View this message in context: http://postgresql.1045698.n5.nabble.com/Java-String-saving-as-unicode-in-database-tp5774370.html > Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com. -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc