pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feed From: parisi@alephint.it
To: pgsql-interfaces@postgresql.org
Subject: JDBC and Applet on Linux-Apache
Date: Thu, 01 Jul 1999 18:08:29 +0100
Message-ID: <fc.004c544d000e8395004c544d000e8395.e8396@alephint.it> (raw )
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(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();
}
}
}
}
Message-ID: <fc.004c544d000e8395004c544d000e8395.e8396@alephint.it>
Permalink: ../fc.004c544d000e8395004c544d000e8395.e8396@alephint.it/
Also on: postgresql.org/message-id/fc.004c544d000e8395004c544d000e8395.e8396@alephint.it
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-interfaces@postgresql.org
Cc: parisi@alephint.it
Subject: Re: JDBC and Applet on Linux-Apache
In-Reply-To: <fc.004c544d000e8395004c544d000e8395.e8396@alephint.it>
References: <fc.004c544d000e8395004c544d000e8395.e8396@alephint.it>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox