The connection is simple, so I will not write it. Thanks for the main implementation, you can use the URL. If you want to see the connection, you can check the next one. Generally, I am not allowed to write it here.
Package cn.edu. nwsuaf. CIE. Aisa. WSC. operation;
Import java. SQL. connection;
Import java. SQL. preparedstatement;
Import java. SQL. resultset;
Import java. SQL. sqlexception;
Import java. util. arraylist;
Import java. util. hashtable;
Import java. util. List;
Import com. MySQL. JDBC. resultsetmetadata;
Public class databaseattribute {
Connectionsource dbconnectionsourceimpl = NULL; // This is defined by an interface.
Resultset = NULL;
Public hashtable <string, Object> ROW = NULL;
Preparedstatement = NULL;
Public list <string> listattributelist = NULL;
Public list <string> getattribute (string tablenamestring ){
Dbconnectionsourceimpl = new dbconnectionsourceimpl ();
Connection connection = dbconnectionsourceimpl. getconnection ();
Try {
Preparedstatement = connection. preparestatement ("select * from"
+ Tablenamestring );
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Resultset = NULL;
Try {
Resultset = preparedstatement.exe cutequery ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Resultsetmetadata metadata = NULL;
Try {
Metadata = (resultsetmetadata) resultset. getmetadata ();
} Catch (sqlexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}
// Map <object, Object> attributemmap = NULL;
Listattributelist = new arraylist <string> ();
Try {
// While (resultset. Next ()){
For (INT I = 1; I <= metadata. getcolumncount (); I ++ ){
// Attributemmap = new hashmap <object, Object> ();
System. Out. println ("metadata. getcolumncount ()" + metadata. getcolumncount ());
System. Out. println (metadata. getcolumnname (I ));
Listattributelist. Add (metadata. getcolumnname (I ));
// Attributemmap. Put (metadata. getcolumnname (I), resultset. GetObject (I ));
}
// Listattributelist. Add (attributemmap );
//}
} Catch (sqlexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}
Try {
Resultset. Close ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Try {
Preparedstatement. Close ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Try {
Connection. Close ();
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Return listattributelist;
}
}