Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC Sequence generator problem
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


harini
Sequence generator problem
1 Answer(s)      4 years and 7 months ago
Posted in : JDBC


Dear sir,
I have created one table by name massemailsendingdetails.

CREATE TABLE MASSEMAILDETAILS(
ID NUMBER,
SUBJECT VARCHAR2(20),
MATTER VARCHAR2(150),
MATTERFILE VARCHAR2(30),
STATUS VARCHAR2(20)
);
Then i created a sequence generator for an id as follows

CREATE SEQUENCE MASSEMAILDETAILS_SEQ START WITH 1 INCREMENT BY 1;

I used the following method to insert a values

public com.antares.DTO.MassMailDetailsDTO insertMassMAilDeails(
String pstrSubject, String pstrMatter, String pstrMatterFile,
String pstrStatus, String strFrom) {

ResultSet resultSet = null;
com.antares.DTO.MassMailDetailsDTO massMailDetails = null;

try {
connection = DBUtil.getOracleConnection();
statement = connection.createStatement();
System.out.println("**** Connection established ***");

int i = statement
.executeUpdate("insert into massemaildetails values(massemaildetails_seq.nextval,'"
+ pstrSubject
+ "','"
+ pstrMatter
+ "','"
+ pstrMatterFile
+ "','"
+ pstrStatus
+ "','"
+ strFrom + "')");
System.out.println("**** statement established is ***" + i);
resultSet = statement
.executeQuery("SELECT * FROM massemaildetails");

while (resultSet.next()) {
massMailDetails = new com.antares.DTO.MassMailDetailsDTO();
massMailDetails.setId(resultSet.getInt("Id"));
massMailDetails.setSubject(resultSet.getString("Subject"));
massMailDetails.setMatter(resultSet.getString("matter"));
massMailDetails
.setMatterFile(resultSet.getString("matterFile"));
massMailDetails.setStatus(resultSet.getString("status"));
massMailDetails
.setEmail_From(resultSet.getString("Email_From"));
}
} catch (SQLException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
return massMailDetails;
}

Its working fine,but problem is that when i insert a values it will work and inserted the values.this one i am showing in a table ,but problem is a that it is also created a new id with a dummy values first and then inserted the values what i have given .I am nt understanding where it is going wrong ..so please help me sir..

Thanks and Regards
Harini Veerapur.

Advertisement
View Answers

June 8, 2010 at 11:38 AM


Hi Friend,

You can simply declare the field 'id' as primary key and set it to Auto increment. Then there will be no need to generate the id values, you will get automatically incremented value.

Hope that it will work.
Thanks


Related Tutorials/Questions & Answers:
Sequence generator problem - JDBC
Sequence generator problem  Dear sir, I have created one...) ); Then i created a sequence generator for an id as follows CREATE SEQUENCE...,but problem is that when i insert a values it will work and inserted
how to use sequence as a generator class in hibernate for ms sql
how to use sequence as a generator class in hibernate for ms sql  Hi... as a generator class for ms sql database. Do we need to create an sequence in mssql prior to use sequence generator class?.If it is mandatory to create an sequence in mssql
Advertisements
Tab sequence problem with Radio buttons - JSP-Servlet
Tab sequence problem with Radio buttons  Hi, I have membership... button) courier delivery courier(radio button) currently tab sequence going from 1 year radiobutton to courier button but tab sequence has to go as from 1
Generator in Hibernate
Generator in Hibernate  What is the generator in hibernate
Data Generator
Data Generator Data Generator is free open source script that is designed to create the application, which can be used to generate a large sum of data... JavaScript, PHP and MySQL. Characteristics Data generator is browser
Define sequence generated primary key in hibernate
="java.lang.Long"> <generator class="sequence"> <param name...Define sequence generated primary key in hibernate  How to define sequence generated primary key in hibernate?   Use value "sequence
Processing Sequence of DispatcherServlet
In this section, you will get to know about the processing sequence of DispatcherServlet
Hibernate Generator
This tutorial is helpful in understanding the concept of hibernate generator
HIbernate call for sequence - Hibernate
HIbernate call for sequence  I have created a sequence in oracle table. Now how to access this in java class through hibernate from dual table i am... the sequence using dual table. Thanks in advance
Understanding Hibernate <generator> element
generator uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi... a named database sequence. uuid The uuid generator uses... about hibernate <generator> method in detail. Hibernate generator element
Hibernate generator Element
; type="long" column="Id" > <generator class=".... sequence In DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL..., short or int. assigned This generator lets to assign an identifier
DNA sequence - Java Beginners
DNA sequence  Write a java program to read a file that contains DNA sequences of arbitrary length one per line (note that each DNA sequence is just a String). Your program should sort the sequences in descending order
hibernate metamodel generator
In this section, you will learn about hibernate metamodel generator
Generator Tag
; } } Create a jsp page where the generator tag...;  Output of the  Generator Tag Example
Wraps a character sequence into a buffer.
Wraps a character sequence into a buffer. In this tutorial you will see how to wraps a character sequence into a buffer. Here in this example a string variable is having a sequence of character which is further wrapped into a buffer
Sequence number to generate daily starting with 1
Sequence number to generate daily starting with 1  Sir, I am creating a bill report Application..I want to generate a sequence number for bill that is starting from 1.and if date changes the sequence number again starts with 1
org.hibernate.MappingException: could not instantiate id generator
" org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
" org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
" org.hibernate.MappingException: could not instantiate id generator
org.hibernate.MappingException: could not instantiate id generator
" org.hibernate.MappingException: could not instantiate id generator
Website Description Data Scraper & Image/Thumbnail Generator
Website Description Data Scraper & Image/Thumbnail Generator   I need Image/Thumbnail Generator code in java. Please help me
Website Description Data Scraper & Image/Thumbnail Generator
Website Description Data Scraper & Image/Thumbnail Generator   This is yhoo I need Image/Thumbnail Generator code in java. Please help me
Counting the highest sequence of zeros and one's - Java Beginners
Counting the highest sequence of zeros and one's  Count the highest sequence value of '0's and '1's. for a given string with zeroes and ones. Input: You should ask user to enter any bit string with zeros and ones sequence
MX Sequence Effect in Flex4
MX Sequence Effect in Flex4: The Sequence effect is used to play multiple effects one after the other according they are added. The tag of Sequence Effect is <mx:Sequence>. In this example you can see how we can use Sequence
Javah -  Header File Generator
Javah -  Header File Generator       In Java programming we need to implement some native methods. You must be wondering about what's native methods.  Firstly, The native
Hibernate generator Element
In this tutorial you will learn about the hibernate's generator element , which is used to auto generate the primary key value
Generator Tag (Control Tags) Example
Generator Tag (Control Tags) Example       In this section, we are going to describe the generator tag. The generator tag...; } } Create a jsp page where the generator tag
Using Hibernate <generator> to generate id incrementally - Struts
) to the class. Here is the example of generator element from our first application..... Mr.Sandeep. we do have many generator algorithms for our id, So you are incrementing id
PHP Simple password generator
PHP Simple password generator In this tutorial I will be showing you how to create a random password using nothing but loops and random letters. For extra security I will define a minimum length and a maximum length, I will also
Generator Tag (Control Tags) Using Count Attributes
Generator Tag (Control Tags) Using Count Attributes       In this section, we are going to describe the generator...;} } Create a jsp page where the generator tag <s
Advertisements
 

 

 

DMCA.com