import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.Properties;
public class Main
{
String dbms;
String host;
String port;
String user;
String password;
public static void main( String args[] )
{
Main m = new Main();
Connection c = null;
try{
m.dbms = "mysql";
m.host = "localhost"; m.port = "3306"; m.user = "root"; m.password = "password";
c = m.getConnection();
SQLTable PstCloudGateway = new SQLTable( "storagegatewaymanager" , "PstCloudGateway" , c );
System.out.println( PstCloudGateway.getTableName() );
System.out.println( "column count = " + PstCloudGateway.getColumnCount() );
ArrayList <SQLColumn> headers = PstCloudGateway.getColumnHeaders();
ListIterator <SQLColumn> it = headers.listIterator();
System.out.println( "Field,Type,Nullable,Key,DefaultValue,Extra" );
while ( it.hasNext () )
{
SQLColumn temp = it.next();
System.out.println( temp.getField() + "," + temp.getType() + "," + temp.getNullable() + "," + temp.getKey() + "," + temp.getDefaultValue() + "," + temp.getExtra() );
}
System.out.println( "row count = " + PstCloudGateway.getRowCount() );
c.close();
}catch( SQLException sqle )
{ System.err.println( sqle.getMessage() );
}
catch( Exception e )
{ System.err.println( e.getMessage() ) ;
}
finally
{
try{
if( c != null ){ c.close(); }
}catch( Exception e )
{}
}
}
protected Connection getConnection() throws SQLException
{
Connection conn = null;
Properties connectionProps = new Properties();
connectionProps.put( "user" , this.user );
connectionProps.put( "password" , this.password );
if( this.dbms.equals( "mysql" ) )
{ conn = DriverManager.getConnection( "jdbc:" + this.dbms + "://" + this.host + ":" + this.port + "/", connectionProps );
}else if( this.dbms.equals( "derby" ) )
{// conn = DriverManager.getConnection( "jdbc:" + this.dbms + ":" + this.dbName + ";create=true", connectionProps );
}
return conn;
}
} //end class