Package cn.edu. nwsuaf. CIE. Aisa. WSC. operation;
Import java. SQL. connection;
Import java. SQL. resultset;
Import java. SQL. sqlexception;
Import com. MySQL. JDBC. databasemetadata;
Public class databasetablenameread {
Connectionsource dbconnectionsourceimpl = NULL;
Public resultset getdatabasetablenameread (){
Dbconnectionsourceimpl = new dbconnectionsourceimpl ();
Connection connection = dbconnectionsourceimpl. getconnection ();
Resultset = NULL;
Try {
Databasemetadata meta = (databasemetadata) connection. getmetadata ();
Resultset = meta. gettables (null,
New String [] {"table "});
While (resultset. Next ()){
System. Out. println ("table name:" + resultset. getstring (3 ));
System. Out. println ("Table Username:" + resultset. getstring (2 ));
System. Out. println ("name:" + resultset. getstring (1 ));
System. Out. println ("------------------------------");
}
Connection. Close ();
} Catch (exception e ){
Try {
Connection. Close ();
} Catch (sqlexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}
// Todo auto-generated Catch Block
E. printstacktrace ();
}
Return resultset;
}
}
Package cn.edu. nwsuaf. CIE. Aisa. WSC. operation;
Import java. SQL. connection;
Import java. SQL. drivermanager;
Import java. SQL. sqlexception;
Import cn.edu. nwsuaf. CIE. Aisa. WSC. informationpushmain. informationpush;
/**
* @ Author ����������ڣ 7-7-14 ��ļ ļ ¼ ������
*/
Public class dbconnectionsourceimpl implements connectionsource {
Proopertiess properties = informationpush. properties;
@ Override
Public connection getconnection (){
// Todo auto-generated method stub
Connection connection = NULL;
If (informationpush. properties. getdatasource (). getdbtype (). Equals ("MySQL ")){
Try {
Class. forname ("com. MySQL. JDBC. Driver ");
} Catch (classnotfoundexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
String url = informationpush. properties. getdatasource (). geturl ();
String usename = informationpush. properties. getdatasource (). getuser ();
String Password = informationpush. properties. getdatasource (). GetPassword ();
Try {
System. Out. println (URL );
Connection = (connection) drivermanager. getconnection (URL,
Usename, password );
Return connection;
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
System. Out. println (E. getmessage ());
E. printstacktrace ();
}
} Else if (informationpush. properties. getdatasource (). getdbtype (). Equals ("sqlserver ")){
Try {
Class. forname ("com. Microsoft. sqlserver. JDBC. sqlserverdriver ");
} Catch (classnotfoundexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}
String url = informationpush. properties. getdatasource (). geturl ();
String user = informationpush. properties. getdatasource (). getuser ();
String Pwd = informationpush. properties. getdatasource (). GetPassword ();
Try {
Connection = drivermanager. getconnection (URL, user, PWD );
Return connection;
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Else if (informationpush. properties. getdatasource (). getdbtype (). Equals ("oracle ")){
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver ");
} Catch (classnotfoundexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}
String url = informationpush. properties. getdatasource (). geturl ();
String user = informationpush. properties. getdatasource (). getuser ();
String Pwd = informationpush. properties. getdatasource (). GetPassword ();
Try {
Connection = drivermanager. getconnection (URL, user, PWD );
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
} Else if (informationpush. properties. getdatasource (). getdbtype (). Equals ("access ")){
Try {
Class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");
} Catch (classnotfoundexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
}
String url = informationpush. properties. getdatasource (). geturl ();
String user = informationpush. properties. getdatasource (). getuser ();
String Pwd = informationpush. properties. getdatasource (). GetPassword ();
Try {
Connection = drivermanager. getconnection (URL, user, PWD );
Return connection;
} Catch (sqlexception e ){
// Todo auto-generated Catch Block
E. printstacktrace ();
}
}
Return connection;
}
}
Package cn.edu. nwsuaf. CIE. Aisa. WSC. operation;
Import java. SQL. connection;
/**
* @ Author
* ����ڣ 7-14
*/
Public interface connectionsource {
Public connection getconnection ();
}