This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

JSP - Unsupported Operation Exception

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

I tried to write a code that reads the data from excel sheet and writes into DB2 database.It worked perfectly .But if it has repetition fields, then also it inserts the data.So I used a primary key in the database to avoid repetition.Then I wrote a code which inserts data into database when there is no repetition of data.But if it contains repeatitive data, then it must rollback all the process in database or remove the data that is inserted through the program.I used save point and rollback for this action.
When i run the program it shows "java.lang.UnsupportedOperationException ".Can anyone help me out.
So my code is


<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html>
<body>
<%
Connection c;
Connection c1;
Statement stmnt;
Statement stmnt1;
Savepoint svpt1=null ;
int r=0;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc dbc:tt","",""); //excel DSN = tt
c1= DriverManager.getConnection("jdbc dbc :db2","",""); //DB2 DSN = db2

stmnt = c.createStatement();
stmnt1 = c1.createStatement();
ResultSet rs = stmnt.executeQuery("SELECT * FROM [Sheet1$]");
try
{
while(rs.next())
{
String a1=rs.getString("percen");
String a2=rs.getString("name");
svpt1 = c1.setSavepoint("first");
r= stmnt1.executeUpdate("INSERT INTO TAB1 VALUES('"+a1+"','"+a2+"');");//insert fields into database DB2
out.println(a1+" "+a2);

}
c1.commit();
response.sendRedirect("index.jsp");

}
catch(Exception e)
{
c1.rollback(svpt1);
}
}
catch(Exception e)
{
out.println(e);
}
%>
</body>
</html>


Manoj



[ October 22, 2008: Message edited by: Potter James ]

[ October 22, 2008: Message edited by: Potter James ]
[ October 22, 2008: Message edited by: Potter James ]
 
Marshal
Posts: 67343
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. This forum is for questions on JSP.

For more information, please read this.

This post has been moved to a more appropriate forum.
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Potter,

You are using the JDBC_ODBC bridge, it does not implement very much.
Here's some code:



cheers,
Herman
 
Potter James
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Herman Scheltinga:
hi Potter,

You are using the JDBC_ODBC bridge, it does not implement very much.
Here's some code:



cheers,
Herman




Can you say that where to insert that clearly..
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using the JDBC ODBC bridge to communicate with DB2? COuld you not just use a proper type 4 driver? As is intimated above, the JDBC ODBC bridge is not production quality.
 
The only thing that kept the leeches off of me was this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!