Sequence generator problem
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 Tutorials/Questions & Answers:
Sequence generator problem - JDBCSequence 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
Advertisements
Tab sequence problem with Radio buttons - JSP-ServletTab
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
ModuleNotFoundError: No module named 'sequence'ModuleNotFoundError: No module named '
sequence' Hi,
My Python... '
sequence'
How to remove the ModuleNotFoundError: No module named '
sequence... to install padas library.
You can install
sequence python with following
HIbernate call for sequence - HibernateHIbernate 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 BeginnersDNA 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