« Return to Thread: getElement from database

Re: getElement from database

by Bryan Hunt-2 :: Rate this Message:

Reply to Author | View in Thread

Gabriele, this type of question is best asked in the newsgroups.  I  
don't see any obvious problems with the code below other than your  
content provider returning a length instead of Object[], but I'm  
guessing that's a typo as that won't even compile.  My guess is that  
the problem is with your label provider.  Does your label provider  
implement ITableLabelProvider?

Bryan

On Jun 13, 2008, at 6:43 AM, gaghi wrote:

>
> hi guys, i'm writing a plugin for udig(based on eclipse). I have to  
> show a
> table which rows are the result of a DB selection. I'm able to get  
> the rows
> from the database, but I think I'm doing something wrong in getting  
> them
> back to the table.
> Following a skeleton of my code.
> CollectionItem defines the type of data.
> getElement is a Content Provider method.
> I don't really know how move on.
> I have problems with LabelProvider which doesn't allow me to show  
> the column
> name because of a casting problem from CollectionItem, but i have a  
> method
> like this: String[] colName= coll_It.getColumnName(); this method  
> returns a
> string array. Trying instead to print a string array {from 1 to 10}  
> the
> label are printed all in the first column filling 10 rows.
> i hope you could help.
>
> public class CollectionItem {
> private ArrayList<Object[]> items= new ArrayList<Object[]>();
> private String collection;
> Object dbRow[]=null;
> public CollectionItem(String collection){
> this.collection=collection;
> extractData();
> }
>
> public ArrayList<Object[]> getItem(){
> return items;
> }
> public void extractData(){
> String query = "SELECT I.* FROM  Items as I  Inner Join  
> CollectionItems AS
> CI  ON I.ItemID = CI.ItemID where CI.CollectionID like \""+collection
> +"\"";
> System.out.println(query);
> try {
> DbAction db= new DbAction("Collezione");
>    Statement s = db.openConnection();
> ResultSet rs = s.executeQuery(query);
> ResultSetMetaData rsmd = rs.getMetaData();
> dbRow= new Object[rsmd.getColumnCount()];
> columnName= new Object[rsmd.getColumnCount()];
> boolean done=false;
> while( rs.next() )
> {
> for(int i =1; i <= rsmd.getColumnCount(); i++){
> dbRow[i-1]=rs.getString(i);
>
> }
>
> items.add(dbRow);//fill vector with array containing rows
>
> }
>
> db.closeConnection();
> }
> catch (SQLException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> }
>
> Inside TableContentProvider:
>
> public Object[] getElements(Object inputElement) {
>
> CollectionItem ci = new CollectionItem(inputElement.toString());
> return ci.getItem().toArray().length;
>
> }
>
> Thanks,
> Gabriele
> --
> View this message in context: http://www.nabble.com/getElement-from-database-tp17820811p17820811.html
> Sent from the Eclipse Platform - swt mailing list archive at  
> Nabble.com.
>
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@...
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@...
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

 « Return to Thread: getElement from database