PDA

Visualizza la versione completa : [JAVA] jdbc


raffaeu
22-07-2004, 14:31
Ciao sto creando una class per connettermi al DB access tramite jdbc, ma mi da errore di sintassi


import java.net.URL.*;
import java.sql.*;

public class Connessione {

public static void main(String argv[]) {
String url = "jdbc:odbc:data";
Connection con;
String queryString;
queryString = "SELECT * FROM PRINCIPALE";
Statement stmt;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e){
System.out.print("ClassNotFoundException :");
System.out.println(e.Message());
}
try{
con = DriverManager.getConnection(url);
stmt = con.createStatement();
ResultSet rs stmt.executeQuery(queryString);

while(rs.next()){
String sNome = rs.getString("NOME");
String sCognome = rs.getString("COGNOME");

System.out.print("Nome : " + sNome);
System.out.print("Cognome : " + sCognome);
System.out.print("\n");
}
stmt.close();
con.close();
}catch(SQLException ex){
System.err.println("SQLException : " + ex.getMessage());
}
}
}

Mi dice :

Connessione.java:21: ';' expected

Ma perchè? Il ; c'è.

raffaeu
22-07-2004, 14:41
Risolto


ResultSet rs = stmt.executeQuery(queryString);

io scrivevo

ResultSet rs stmt.executeQuery(queryString);

Loading