Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to delete data from a dbase

 
vikas de
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("jdbcdbc: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
 
Monty Ireland
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. )
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic