aspose file tools*
The moose likes JDBC and the fly likes help! how to detect new document_id Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "help! how to detect new document_id" Watch "help! how to detect new document_id" New topic
Author

help! how to detect new document_id

laue huang
Greenhorn

Joined: Nov 19, 2003
Posts: 2
what's the problems and how to slove them, thanks in advance.
public class DBTopicExtraction extends DBSimpleConnector {
int documentID;
// document list is used for saving documents
ArrayList documentList = new ArrayList();
// new document
Document doc = new Document( documentID );
//Constructor
public DBTopicExtraction() {
super(
"Lexikon",
DBConfig.getConnectionDriver(),
DBConfig.getConnectionURL(),
DBConfig.getUser(),
DBConfig.getPassword());
this.open();
}
public void getIDF() {
try {
//execute SQL statements
StringBuffer sql = new StringBuffer();
sql.append("SELECT ")
.append("TTD.DOCUMENT_ID, ")
.append("IT.TERM, ")
.append("TTD.IDF ")
.append(" FROM INDEX_TERMS IT, TERM_TO_DOCUMENT TTD ")
.append("WHERE TTD.TERM_ID = IT.TERM_ID");
//.append("ORDER BY TTD.DOCUMENT_ID");
// process the statement
ResultSet result = this.executeQuery(sql.toString());
Token token = null;
// new sentence
Sentence sentence = new Sentence();
//process the following results
while (result.next()) {

// get document id
//int documentID = result.getInt(1);
// insert document to list
//documentList.add(doc);
String term = result.getString(2);
double idf = result.getDouble(3);
token = new Token(term, idf);
sentence.addToken(token);
if (doc.checkEndSentence(token.getTerm())) {
// add sentence to document
doc.addSentence(sentence);
// new sentence
sentence = new Sentence();
}
}
//System.out.print(document_id + "\t");
System.out.println(sentence.toString() + "\t =Sentence=");
result.close();
} catch (SQLException e) {
Log.errorOut(this, "Error", e);
}
}
public ArrayList getDocumentList() {
try {
//execute SQL statements
StringBuffer sql = new StringBuffer();
sql
.append("SELECT ")
.append("TTD.DOCUMENT_ID")
.append(" FROM INDEX_TERMS IT, TERM_TO_DOCUMENT TTD ")
.append("WHERE TTD.TERM_ID = IT.TERM_ID ")
.append("ORDER BY TTD.DOCUMENT_ID");
// process the statement
ResultSet result = this.executeQuery(sql.toString());
while (result.next()) {
// get document id
int documentID = result.getInt(1);
// check if it mets new documenten id
//for (int i = 0; i < documentID; i++) {
// insert document to list
//documentList.add(doc);
//}
}
result.close();
} catch (SQLException e) {
Log.errorOut(this, "Error", e);
}
return documentList;
}
// main method
public static void main(String[] args) {
DBTopicExtraction db = new DBTopicExtraction();
// output the results
System.out.println("===Result===");
ArrayList documentList = db.getDocumentList();
// for each element of documentList
Iterator it = documentList.listIterator();
Document document;
while (it.hasNext()) {
document = (Document) it.next();

//insert document to list
documentList.add(doc);
db.getIDF();
}
}
}
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Laue
Firstly, can you edit your post and use the UBB code tags so that the code you posted is more readable.
Second, what is wrong with your program? does it compile? Does it run at all and just give you the wrong results. It looks like your class extends another class and calls methods in that one, depending on what is wrong with your code they may or may not be relevant. Let us know exactly hat is wrong and then we can go from there.


Dave
laue huang
Greenhorn

Joined: Nov 19, 2003
Posts: 2
thank you Dave,
sorry, I am a new java beginner. The program has been compiled, no mistake. but the result isn't right.
So I want to use it to connect with oracle database and execute some sql statements. I have writen 3 class Document, Sentence, Token which help me to analyse the elements(terms). I should get the IDF(each word has its idf, then I caculate the summe of the whole sentence if it mets the end-token) for each sentence. As the result I should check all the documents.
just like
---------
doc_id idf sentence
1 20.9 hallo...world!
1 22 dddd...connection.
By now I got some problems to detect new document_id because there are more documents in the database. I have tried to use ArrayList to save the documentList, but it didn't work,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help! how to detect new document_id