Home Answers Viewqa JDBC Sequence generator problem

 
 


harini
Sequence generator problem
1 Answer(s)      2 years and 11 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.
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 Pages:
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
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
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
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
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
Processing Sequence of DispatcherServlet
In this section, you will get to know about the processing sequence of DispatcherServlet
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
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 Generator
This tutorial is helpful in understanding the concept of hibernate generator
hibernate metamodel generator
In this section, you will learn about hibernate metamodel generator
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
Generator Tag
; } } Create a jsp page where the generator tag...;  Output of the  Generator Tag Example
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
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
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
code problem - Java Beginners
code problem  Dear sir, i'm making a program where characters of a string are being displayed having its length thru a loop, like- s a t i s h i want to store them as sequence in a StringBuffer like "satish" how
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
i need help to solve this problem
after perform each of the following sequence of events: a. start with an empty... Test the array queue implementation with the sequence of events described above
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
linked list example problem - Java Beginners
of the list in a comma-separated sequence, in the following format: [elem0
linked list example problem - Java Beginners
of the list in a comma-separated sequence, in the following format: [elem0
JNIUS Model Driven Development Generator
JNIUS Model Driven Development Generator       JNIUS Generator is an Eclipse plugin for MDD (Model Driven Development). The data models can be : a UML file (XMI format
Generator Tag (Control Tags) Using an Iterator with Id Attributes
Generator Tag (Control Tags) Using an Iterator with Id Attributes... the generator tag using the id attributes.  Add the following code...;} } Create a jsp page where the generator tag <s:generator>
Exercise - Count Words
Java: Exercise - Count Words Problem Write a method which counts the number of words in a string. Assume that a word is defined as a sequence of letters. Signature public static int countWords(String s) Note
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
problem in validation
problem in validation  sir/madam, i m using struts-1.3.10. i m getting a problem my properties file is not found.... while i hav configuired it in struts-config.xml file, like thanks n regards himanshu
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.