• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

how to delete data from a dbase

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear friends,
did somebody know how to delete a specific data from a dbase
please see the code...
import java.sql.*;
class oraclepro
{
String s="6a";
Connection conn;
PreparedStatement stmt;
ResultSet rs;
public oraclepro()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:pro");
stmt=conn.prepareStatement("select * from klasseTable");
rs=stmt.executeQuery();
while(rs.next())
{
if(s==rs.getString(1))
int result=stmt.executeUpdate("delete from klasseTable where klasse=s");
}
}catch(Exception e){System.out.println(e);}
}

public static void main(String arg[])
{
oraclepro o =new oraclepro();
}
}
it displays the following errors
oraclepro.java:19: '.class' expected
int result=stmt.executeUpdate("delete from klasseTable where klasse=s");
^
oraclepro.java:19: not a statement
int result=stmt.executeUpdate("delete from klasseTable where klasse=s");
^
2 errors
thanx a lot...
vikas
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are confused as to how to use JDBC statements.
The statement interface represents the basic SQL statement that can be executed. The preparedstatement represents a type of Statement that can be precompiled with query informnation as performance enhancement.. The callablestatement is a type of preparedstatement that serves to encapsulate execution of stored procedures in a database.
I think you should stick with the basic statement.
FYI....
ResultSet rs = statement.execQuery( sqlString ) allows the execution of a query and obtain a resultset.
int nValue = statement.execUpdate( sqlString ) allows on to execute a query (insert,delete,update) and then obtain a count of updated rows processed.
boolean returnvalue = statement.execute( sqlString) is the most generic way to execute a sql statement. Returning a true/falue if execution returns a result set.
For more information... please review the demoDB application within you JDK examples.
Hope this helps...
Monty
------------------
Multi-Platform Database Developer ( on E.S.T. )
 
vikas de
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how must i change my code that it runs sucessfully...???
 
Monty Ireland
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please review the following code examples in
%java_home%\demo\jfc\dbbdemo.
Lots of sample code.
Good-Luck... Here to help
Monty

------------------
Multi-Platform Database Developer ( on E.S.T. )
 
Of course, I found a very beautiful couch. Definitely. And 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!