pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Insert null in int column
4+ messages / 3 participants
[nested] [flat]

* Insert null in int column
@ 2010-11-22 17:50 venkata siva prasad <vsp_29@rediffmail.com>
  2010-11-22 18:52 ` Re: Insert null in int column Maciek Sakrejda <msakrejda@truviso.com>
  2010-11-22 19:56 ` Re: Insert null in int column dmp <danap@ttc-cmc.net>
  0 siblings, 2 replies; 4+ messages in thread

From: venkata siva prasad @ 2010-11-22 17:50 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

I have created the table as below.

create table test(id numeric(4),name character varying(8));

I need to insert null as below.

insert into test values(null,'aaa');

But&nbsp; I am getting error as "Integer expecting..."


Can you please help me on this.

Regards,
Prasad
  

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Insert null in int column
  2010-11-22 17:50 Insert null in int column venkata siva prasad <vsp_29@rediffmail.com>
@ 2010-11-22 18:52 ` Maciek Sakrejda <msakrejda@truviso.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Maciek Sakrejda @ 2010-11-22 18:52 UTC (permalink / raw)
  To: venkata siva prasad <vsp_29@rediffmail.com>; +Cc: pgsql-jdbc

1. Is this a jdbc-specific issue? If so, please post the Java code,
not just SQL. If not, this is not the right list (try pgsql-general or
pgsql-novice).
2. This works fine for me (verbatim) in psql.

---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Insert null in int column
  2010-11-22 17:50 Insert null in int column venkata siva prasad <vsp_29@rediffmail.com>
@ 2010-11-22 19:56 ` dmp <danap@ttc-cmc.net>
  2010-11-22 20:04   ` Re: Insert null in int column dmp <danap@ttc-cmc.net>
  1 sibling, 1 reply; 4+ messages in thread

From: dmp @ 2010-11-22 19:56 UTC (permalink / raw)
  To: venkata siva prasad <vsp_29@rediffmail.com>; +Cc: pgsql-jdbc

Hello Prasad,

Attached class that should demostrate the insert you desire. The
insertion for Postgresql via SQL can be done through two different
methods.

Singular Example:
INSERT/REPLACE INTO "bigInt_types" ("data_type_id", "bigint_type") VALUES (NULL, 
'5');
INSERT/REPLACE INTO "bigInt_types" ("data_type_id", "bigint_type") VALUES (NULL, 
'-65');

Plural Example:
INSERT/REPLACE INTO "bigInt_types" ("data_type_id", "bigint_type") VALUES (NULL, 
'5'),(NULL, '-65');

danap.

venkata siva prasad wrote:
> Hi,
>
> I have created the table as below.
>
> create table test(id numeric(4),name character varying(8));
>
> I need to insert null as below.
>
> insert into test values(null,'aaa');
>
> But I am getting error as "Integer expecting..."
>
>
> Can you please help me on this.
>
> Regards,
> Prasad
>
> <http://sigads.rediff.com/RealMedia/ads/click_nx.ads/www.rediffmail.com/signatureline.htm@Middle?;
>

Attachments:

PostgreSQL_JDBC2.java (text/plain, 5.9K) download //================================================================= // PostgreSQL_JDBC Class //================================================================= // // This class is used to control the running of the a generic // class to access the PostgreSQL database. // // << PostgreSQL_JDBC.java >> // //================================================================= // Copyright (C) 2005-2010 Dana M. Proctor // Version 1.01 02/13/2010 // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version // 2 of the License, or (at your option) any later version. This // program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty // of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See // the GNU General Public License for more details. You should // have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // (http://opensource.org) // //================================================================= // Revision History // Changes to the code should be documented here and reflected // in the present version number. Author information should // also be included with the original copyright author. //================================================================= // Version 1.0 12/23/2008 PostgreSQL Connection Main Application. // 1.1 02/13/2010 Generalized to be Used With Any Test Case. // 1.2 03/15/2010 Explicit Exception Output in main() & No // New Instance for Class.forName(). // 1.3 11/22/2010 Added testNullInsert(). // //----------------------------------------------------------------- // danap@dandymadeproductions.com //================================================================= //================================================================= // PostgreSQL_JDBC Application //================================================================= import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * The PostgreSQL class is used to control the running of the a generic class to * access the PostgreSQL database. Arguments -debug. * @author Dana M. Proctor * @version 1.3 11/22/2010 */ class PostgreSQL_JDBC2 { //============================================ // Creation of the necessary class instance. //============================================= //============================================================== // PostgreSQL_JDBC Constructor //============================================================== public PostgreSQL_JDBC2(Connection con) { testNullInsert(con); } //============================================================== // Test Methods //============================================================== private void testNullInsert(Connection con) { // Method Instances String sqlStatementString; Statement sqlStatement; ResultSet rs; String identifierQuoteString = "\""; try { // Setup a connection statement. sqlStatement = con.createStatement(); sqlStatementString = "INSERT INTO " + identifierQuoteString + "public" + identifierQuoteString + "." + identifierQuoteString + "test" + identifierQuoteString + " (" + identifierQuoteString + "id" + identifierQuoteString + "," + identifierQuoteString + "name" + identifierQuoteString + ") VALUES (null,'" + "aaa')"; System.out.println(sqlStatementString); rs = sqlStatement.executeQuery(sqlStatementString); rs.close(); sqlStatement.close(); } catch (SQLException sqle) { System.out.println("SQL Exeception" + sqle); } } //============================================================ // Main public access point method for instantiating the // PostgreSQL_JDBC application. Arguments: database, username, // & password. //============================================================== public static void main(String[] args) { String host, database, username, password; Connection dbConnection; // Collect connection properties. and setup connection. host = "localhost"; dbConnection = null; if (args.length != 0) { database = args[0]; username = (args.length > 1) ? args[1] : null; password = (args.length > 2) ? args[2] : null; } else { database = "my_database"; username = "user"; password = "password"; } try { Class.forName("org.postgresql.Driver"); } catch (ClassNotFoundException cne) {System.out.println("ClassNotFoundException" + cne.toString());} // Try to make a connection. try { dbConnection = DriverManager.getConnection("jdbc:postgresql://" + host + "/" + database, username, password); // Connection Good. if (dbConnection != null) { System.out.println("Connection Created"); // Go Do Something. new PostgreSQL_JDBC(dbConnection); // Close. dbConnection.close(); System.out.println("Connection Closed"); } } catch (SQLException sqle) {System.out.println("SQLExeception" + sqle.toString());} } }
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Insert null in int column
  2010-11-22 17:50 Insert null in int column venkata siva prasad <vsp_29@rediffmail.com>
  2010-11-22 19:56 ` Re: Insert null in int column dmp <danap@ttc-cmc.net>
@ 2010-11-22 20:04   ` dmp <danap@ttc-cmc.net>
  0 siblings, 0 replies; 4+ messages in thread

From: dmp @ 2010-11-22 20:04 UTC (permalink / raw)
  To: venkata siva prasad <vsp_29@rediffmail.com>; +Cc: pgsql-jdbc

Sorry,

In the code should have used:

sqlStatement.executeUpdate(sqlStatementString);

Don't need the ResultSet, rs.

danap

dmp wrote:
> Hello Prasad,
>
> Attached class that should demostrate the insert you desire. The
> insertion for Postgresql via SQL can be done through two different
> methods.
>
> Singular Example:
> INSERT/REPLACE INTO "bigInt_types" ("data_type_id", "bigint_type")
> VALUES (NULL, '5');
> INSERT/REPLACE INTO "bigInt_types" ("data_type_id", "bigint_type")
> VALUES (NULL, '-65');
>
> Plural Example:
> INSERT/REPLACE INTO "bigInt_types" ("data_type_id", "bigint_type")
> VALUES (NULL, '5'),(NULL, '-65');
>
> danap.
>
> venkata siva prasad wrote:
>> Hi,
>>
>> I have created the table as below.
>>
>> create table test(id numeric(4),name character varying(8));
>>
>> I need to insert null as below.
>>
>> insert into test values(null,'aaa');
>>
>> But I am getting error as "Integer expecting..."
>>
>>
>> Can you please help me on this.
>>
>> Regards,
>> Prasad




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2010-11-22 20:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-11-22 17:50 Insert null in int column venkata siva prasad <vsp_29@rediffmail.com>
2010-11-22 18:52 ` Maciek Sakrejda <msakrejda@truviso.com>
2010-11-22 19:56 ` dmp <danap@ttc-cmc.net>
2010-11-22 20:04   ` dmp <danap@ttc-cmc.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox