JDBC and Applet on Linux-Apache

From: parisi(at)alephint(dot)it (Tommaso Parisi)
To: pgsql-interfaces(at)postgresql(dot)org
Subject: JDBC and Applet on Linux-Apache
Date: 1999-07-01 17:08:29
Message-ID: fc.004c544d000e8395004c544d000e8395.e8396@alephint.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)mbr(dot)sigea(dot)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(new FlowLayout(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(new Label("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("FATTA CONNESSIONE");
Statement statement = connection.createStatement();
results.setText("CREATO STATEMENT");
String sql=sqlStatement.getText();
boolean hasResults = statement.execute(sql);
results.setText("ESEGUITO STATEMENT SQL");
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("PRESO COMANDO SUBMIT QUERY");
results.setText("I"+"\n");

if(s=="Submit query."){
processQuery();
}
}
}
}

Browse pgsql-interfaces by date

  From Date Subject
Next Message JT Kirkpatrick 1999-07-01 19:16:18
Previous Message JT Kirkpatrick 1999-07-01 12:38:41 RE: [ADMIN] RE: [SQL] float4