File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes how to delete data from a dbase Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to delete data from a dbase" Watch "how to delete data from a dbase" New topic
Author

how to delete data from a dbase

vikas de
Ranch Hand

Joined: Feb 07, 2001
Posts: 39
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

Joined: Oct 03, 2000
Posts: 161
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. )


Multi Platform Database Developer & DBA on E.S.T.
vikas de
Ranch Hand

Joined: Feb 07, 2001
Posts: 39
how must i change my code that it runs sucessfully...???
Monty Ireland
Ranch Hand

Joined: Oct 03, 2000
Posts: 161
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. )
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to delete data from a dbase