JDBC and Applet on Linux-Apache - Mailing list pgsql-interfaces
From | parisi@alephint.it (Tommaso Parisi) |
---|---|
Subject | JDBC and Applet on Linux-Apache |
Date | |
Msg-id | fc.004c544d000e8395004c544d000e8395.e8396@alephint.it Whole thread Raw |
List | pgsql-interfaces |
Hi everybody, I`ve a problem with an applet that simply connect itself to a postgres DB and receive the result of a SQL query.\\ Applet on Netscape give me the error: java.sql.SQLException: No suitable driver catched for the code Class.forName("postgresql.Driver") The incredible thing is that an application with the same code run correctly on the same machine!! Have anybody some suggestion? Thanks for the time, Filippo filippo@mbr.sigea.it Follow the code... P.S. import java.applet.*; import java.awt.*; import java.awt.event.*; import java.sql.*; //import postgresql.Driver.*; public class SQL extends Applet {Label blankLine = new Label(" ");TextField hostPort = new TextField(50);TextField dsn =new TextField(25);TextField sqlStatement = new TextField(50);TextArea results = new TextArea(20,70);Button submitButton= new Button("Submit query.");public void init() { Panel topPanel = new Panel(); Panel bottomPanel = new Panel();Panel topPanels[] = new Panel[4]; for(int i=0;i<topPanels.length;++i){ topPanels[i]=new Panel(); topPanels[i].setLayout(newFlowLayout(FlowLayout.LEFT)); } topPanel.setLayout(new GridLayout(4,1)); topPanels[0].add(new Label("host:port")); topPanels[0].add(hostPort); topPanels[1].add(new Label("data set ")); topPanels[1].add(dsn); topPanels[2].add(newLabel("SQL statement ")); topPanels[2].add(sqlStatement); submitButton.addActionListener(new ButtonHandler());topPanels[3].add(submitButton); for(int i=0;i<topPanels.length;++i) topPanel.add(topPanels[i]); bottomPanel.add(results);setLayout(new BorderLayout()); add("North",topPanel); add("South",bottomPanel);}void processQuery(){try{ Class.forName("postgresql.Driver"); results.setText("CARICATO DRIVER"); String url="jdbc:postgresql://"+hostPort.getText()+"/"; url+="conn?dbtype=odbc&dsn='"+dsn.getText()+"'"; // String url="jdbc:postgresql://localhost:5432/mon"; Connection connection=DriverManager.getConnection(url,"tommy",""); results.setText("FATTACONNESSIONE"); Statement statement = connection.createStatement();results.setText("CREATO STATEMENT"); String sql=sqlStatement.getText(); boolean hasResults = statement.execute(sql);results.setText("ESEGUITO STATEMENTSQL"); if(hasResults){ ResultSet result = statement.getResultSet(); if(result!=null) displayResults(result); }else results.setText(""); connection.close(); }catch(Exception ex){ results.setText("PROVA!"); results.setText(ex.toString());}} void displayResults(ResultSet r) throws SQLException { ResultSetMetaData rmeta = r.getMetaData(); int numColumns=rmeta.getColumnCount();String text=""; for(int i=1;i<=numColumns;++i) { if(i<numColumns) text+=rmeta.getColumnName(i)+"| "; else text+=rmeta.getColumnName(i); } text+="\n"; while(r.next()){ for(int i=1;i<=numColumns;++i){ if(i<numColumns) text+=r.getString(i)+" | "; else text+=r.getString(i).trim(); } text+="\n";} results.setText(text);} class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e){ String s = e.getActionCommand();results.setText("PRESOCOMANDO SUBMIT QUERY");results.setText("I"+"\n"); if(s=="Submit query."){ processQuery(); } }} }
pgsql-interfaces by date: