source file name:  JdbcFlexible.java

import java.sql.*;

 class JdbcFlexible 

{

Connection conn;

Statement st;

String s="";

public JdbcFlexible(String str)

{

s=str;

try

{

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

conn = DriverManager.getConnection("jdbc:odbc:javadsn");

st = conn.createStatement();

if(s.startsWith("select"))

{

ResultSet rs=st.executeQuery(s);

while(rs.next())

{

System.out.println(rs.getString(1)+" "+rs.getString(2)+ " "+rs.getString(3));

}

}

else

st.executeUpdate(s);  

conn.close();

st.close();

}

catch(SQLException  e)

{System.out.println(e); }

catch(Exception e1)

{System.out.println(e1);}


}

public static void main(String[] args)

{

String str=args[0];

System.out.println(str);

JdbcFlexible f=new JdbcFlexible(str);

}

}

output: