/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package koerapakett; import java.sql.*; /** * * @author turing */ public class tabelinaitaja { String sqllause; Connection looYhendus() throws SQLException{ return DriverManager.getConnection( "jdbc:derby://localhost:1527/sample", "app", "app"); } public void paneLause(String uuslause){ sqllause=uuslause; } public String andmedTabelina(){ try{ if(sqllause==null){return "SQL lause puudub";} StringBuffer sb=new StringBuffer(); sb.append(""); Statement st=looYhendus().createStatement(); ResultSet rs=st.executeQuery(sqllause); ResultSetMetaData rms=rs.getMetaData(); sb.append(""); for(int i=1; i<=rms.getColumnCount(); i++){ sb.append(""); } sb.append(""); while(rs.next()){ sb.append(""); for(int i=1; i<=rms.getColumnCount();i++){ sb.append(""); } sb.append(""); } sb.append("
"+rms.getColumnName(i)+"
"+rs.getObject(i)+"
"); return sb.toString(); }catch(Exception ex){ return ex.getMessage(); } } }