sort and select in database..

hi All...

i write a coding that store data in database, that i have two column rule and weight. after that, i want to display the data with weight sorting ascending and select distinct rule.

but it's not working. nothings error but it don't do nothing.

is it wrong with my sql statement?

publicvoid insertDatabase(Vector rule,double weight){

try{

String sqlInsert ="INSERT INTO Sheet2 ( Rule, Weight ) " +

"VALUES ( '"+ rule +"', '" + weight +"' )";

int row = myStatement.executeUpdate(sqlInsert);myResultSetDisplay = myStatement.executeQuery("Select * from Sheet2");

myResultSetSort = myStatement.executeQuery("SELECT * FROM Sheet2 ORDER by Pemberat ASC");

myResultSetDistinct = myStatement.executeQuery("SELECT DISTINCT Petua FROM Sheet2");

}

catch(SQLException e){

System.out.println(e.getMessage());

}//catch

}

[1490 byte] By [rieziesa] at [2007-11-27 3:39:38]
# 1

Print the complete SQL statement to console, copypaste it from the console and execute it straight in the DB using an admin tool.

Does it work? Then likely there is something wrong in the javacode. Run a debugger or play with sysouts.

Does it not work? Then the SQL statement is invalid or the DB simply doesn't contain the expected results.

BalusCa at 2007-7-12 8:43:00 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

i'm just a beginner so i'm sorry. i don't really understand what you want me to do.

how to use admin tool or debugger?

so, i just add setAutoCommit at my coding.

...

myResultSetDistinct = myStatement.executeQuery("SELECT DISTINCT Rule FROM Sheet2");

myConnect.setAutoCommit(false);

and i got error that

[Microsoft][ODBC Microsoft Access Driver]Attribute cannot be set now

rieziesa at 2007-7-12 8:43:00 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3

> how to use admin tool

I was talking about the admin tool of the database.

> or debugger?

If you're using an IDE, like Eclpise, you can use the built-in debugger to execute the code step by step.

> and i got error that

> [Microsoft][ODBC Microsoft Access Driver]Attribute

> cannot be set now

The message is clear. It's too late to set the attribute. You already have issued some actions on the connection. Rearrange your logic.

BalusCa at 2007-7-12 8:43:00 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...