Sorting data in MS-Access using java.

Hi everyone, Can anybody assisst me, how i can sort my table (which is in MS-Access) in ascending order through my java application.Please provide me as soon as possible.Thanx in advance.Khiz_eng
[243 byte] By [khiz_eng] at [2007-9-26 2:05:45]
# 1

If you want to obtein a ResultSet with the records of the table sort by one of the colums you could try this out:

Connection con=getConnection();//getConnection() is the method where you get the connection with de Ms-Access

String sql="SELECT * FROM TABLE ORDER BY COLUMN ASC";

PreparedStatement stmt = con.prepareStatement(sql);

ResultSet rs=stmt.executeQuery();

I hope this will help,Marta

martagle at 2007-6-29 8:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2
Hi Marta,Thanx a lot, i need some with respect to this, how iam going to show the record exactly it appears in MS-Access.Thanx alot again.Khiz_eng
khiz_eng at 2007-6-29 8:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Hi Marta,Thanx a lot, i need some with respect to this, how iam going to show the record exactly it appears in MS-Access.Thanx alot again.Khiz_eng
khiz_eng at 2007-6-29 8:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

If you need the same results in different orders then have 2 ResultSets with 2 different statements.

eg.

String sql1="SELECT * FROM TABLE ORDER BY COLUMN ASC";

PreparedStatement s1 = con.prepareStatement(sql1);

ResultSet r1=s1.executeQuery();

String sql2="SELECT * FROM TABLE";

PreparedStatement s2 = con.prepareStatement(sql2);

ResultSet r2=s2.executeQuery();

the first one is sorted, the second is "as is" in the DB.

hope this helps,

Jamie

jlrober at 2007-6-29 8:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Hi,Thanx again, i want to present the record set as MS-Access with same presentation in GUI.Thanx in advance.Khiz_eng
khiz_eng at 2007-6-29 8:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 6

Hi,

I don't know exactly what you want to do. If you want to insert each record in some conteiner you've defined or in a text o something like that, I can give you code of how to move along the records and all the colums of each record:

while (rs.next())//rs is the ResultSet

{

Hashtable hElemento=new Hashtable();

ResultSetMetaData rsMeta=rs.getMetaData();

for (int iCont=1;iCont=rsMeta.getColumnCount()+1;iCont++)

{

String sClave=rsMeta.getColumnName(iCont);

if (rs.getObject (iCont)!=null)

{

hElemento.put (sClave, rs.getObject (iCont));//here instead of inserting the column of the

//record in a hastable you can insert it in a GUI object

}

else

{

hElemento.put (sClave, "");

}

}

}

I hope this is what you needed.MArta

martagle at 2007-6-29 8:51:07 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...