Newsgroup: it.comp.java
Titolo: Jdbc-Odbc

Sto cercando di connettermi ad un db access locale.....
vorrei utilizzare i driver standard jdbc-odbc---purtroppo ottengo un
errore e non riesco a tirare fuori nessun dato ,...allego
l'applet....:
import java.awt.*;
import java.applet.*;
import java.sql.*;
import java.awt.event.*;
public class sql extends Applet
{
  TextField txUser = new TextField();
  TextField txres = new TextField();
  TextField txPass = new TextField();
  Button btnSubmit = new Button("Submit");
 
 
  public void init()
  {
    builtGUI();
  }
 
 
 
  void builtGUI()
  {
	this.setLayout(null);  
    setSize(WIDTH,HEIGHT);
	txUser.setBounds(10,5,150,25);
	txres.setBounds(10,125,150,25);
    txPass.setBounds(10,50,150,25);
	txPass.setEchoChar('*');
    btnSubmit.setBounds(10,95,150,25);
	btnSubmit.addActionListener(new ButtonHandler());
	this.add(txUser);
    this.add(txPass);
    this.add(btnSubmit);
	this.add(txres);
  }	
 
  class ButtonHandler implements ActionListener
  {
	public void actionPerformed(ActionEvent e)
	{
		String s = e.getActionCommand();
		{
			if("Submit".equals(s))
			{	
				String u = txUser.getText();
				String p = txPass.getText();
				if("alex".equals(u) &&
"alex".equals(p))
				{
					txUser.setText("Bravooooo");
					txPass.setText("");
					processQuery();
				}	
				else
				{	
					txUser.setText("");
					txPass.setText("");
				}	
			}	
		}	
	}	
  }	  
 
   void processQuery()   
   {
	try {   
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	String url="jdbc:odbc:password";
	Connection connection=DriverManager.getConnection(url);
	Statement statement=connection.createStatement();
	String sql="SELECT * FROM utenti WHERE (user='alex')";
	boolean hasresult = statement.execute(sql);
	ResultSet result = statement.getResultSet();
	displayresult(result);
	connection.close();
  }	  
  catch(Exception ex){ txres.setText(ex.toString());
}  
 
}
 
   void displayresult(ResultSet r) throws SQLException
   {
	   String text="";
	   ResultSetMetaData rmeta = r.getMetaData();
	   int numColumns =rmeta.getColumnCount();
	   for(int i=1;i<numColumns;++i) {
		   if(i<numColumns)
				text+=r.getString(i);
	   }	   
	   txres.setText(text);
   }
 
 
}
grazie 
aLeX

Io ho seguito questa struttura di programma dopo aver definito,
tramite la gestione "ODBC 32" , il legame tra nomeDatabase e il db fisico.
public class Prova {
	Connection con;
	Statement stmtSel;
	Prova() {
		try {
		    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 
con=DriverManager.getConnection("jdbc:odbc:nomeDatabase"); // Def. db
		}
		catch (ClassNotFoundException e) {
		    System.err.println("Prova: " + e.getMessage());
		}
		catch (SQLException e) {
		    System.err.println("Prova: " + e.getMessage());
		}
--
Posted from 
ultra1.its.it
 [151.92.2.43]
via Mailgate.ORG Server - 
http://www.mailgate.org

On 14 May 1999 14:12:52 +0200, 
pers.s...@fiatgsa.it
 (SIGEP01 Pers)
wrote:

Ho provato ad utilizzare il tuo consiglio,...ed infatti non da'
errore,..ma non riesco e recuperare i dati,....
ti allego il programma  modificato....e' corretto ?
import java.awt.*;
import java.applet.*;
import java.sql.*;
import java.awt.event.*;
public class sql extends Applet
{
  TextField txUser = new TextField();
  TextField txres = new TextField();
  TextField txPass = new TextField();
  Button btnSubmit = new Button("Submit");
  Connection con;
  Statement stmtSel;

	try {   
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	con=DriverManager.getConnection("jdbc:odbc:nomeDatabase");
	String sql="SELECT * FROM utenti WHERE (user='alex');";
	boolean hasresult = stmtSel.execute(sql);
	ResultSet result = stmtSel.getResultSet();
	displayresult(result);
	con.close();
 
	}
		catch (ClassNotFoundException e) {
		    System.err.println("Prova: " + e.getMessage());
		}
		catch (SQLException e) {
		    System.err.println("Prova: " + e.getMessage());
		}
}
 


		try {
		    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		    con=DriverManager.getConnection("jdbc:odbc:titolidb");
		    stmtSel=con.createStatement();
		}
		catch (ClassNotFoundException e) {
		    System.err.println("Bwa: " + e.getMessage());
		}
		catch (SQLException e) {
		    System.err.println("Bwa: " + e.getMessage());
		}
I tuoi problemi forse derivano dal fatto che non scorri sul cursore aperto
con il
metodo executeQuery.
		String sqlselect  = "Select nominativo from
clienti_anagrafica " +
			     "where tipoCliente= 'lista' order by
nominativo" ;
		try {
		    ResultSet rs=stmtSel.executeQuery(sqlselect);
		    // Parte che forse ti manca ...
		    while (rs.next()) {
			String str=rs.getString(1);
			ecc. ecc. ecc.
