if (conexion != null)
{
Statement stmt = conexion.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM contactos");
ResultSetMetaData md = rs.getColumnCount();
int columnCount = md.getColumnCount();
Vector columns = new Vector(columnCount);
for (int i = 1; i < columnCount; i++)
columns.add(md.getColumnName(i));
Vector data = new Vector();
Vector row;
while (rs.next())
{
row = new Vector(columnCount);
for (int i = 1; i < columnCount; i++)
{
row.add(rs.getString(i));
}
data.add(row);
rs.close();
stmt.close();
conexion.close();
JTable table = new JTable(data, columns);
JScrollPane scrollPane = new JScrollPane(table);
getContentPane().add(scrollPane);
} // fin del while
// se agrega un escuchador para cerrar la ventana con la x de arriba
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
} // fin del if
} // fin del try
catch (InstantiationException ex)
{
}
catch (IllegalAccessException ex)
{
}
catch (SQLException ex)
{
}
catch (ClassNotFoundException ex)
{
}
}
}
TableConnection1.java:27: cannot find symbol
symbol : class Connection
location: class TableConnection1
Connection conexion = null;
^
TableConnection1.java:32: cannot find symbol
symbol : variable DriverManager
location: class TableConnection1
conexion = DriverManager.getConnection(url, usuario, clave);
^
TableConnection1.java:36: cannot find symbol
symbol : class Statement
location: class TableConnection1
Statement stmt = conexion.createStatement();
^
TableConnection1.java:37: cannot find symbol
symbol : class ResultSet
location: class TableConnection1
ResultSet rs = stmt.executeQuery("SELECT * FROM contactos");
^
TableConnection1.java:38: cannot find symbol
symbol : class ResultSetMetaData
location: class TableConnection1
ResultSetMetaData md = rs.getColumnCount();
^
TableConnection1.java:41: cannot find symbol
symbol : class Vector
location: class TableConnection1
Vector columns = new Vector(columnCount);
^
TableConnection1.java:41: cannot find symbol
symbol : class Vector
location: class TableConnection1
Vector columns = new Vector(columnCount);
^
TableConnection1.java:47: cannot find symbol
symbol : class Vector
location: class TableConnection1
Vector data = new Vector();
^
TableConnection1.java:47: cannot find symbol
symbol : class Vector
location: class TableConnection1
Vector data = new Vector();
^
TableConnection1.java:48: cannot find symbol
symbol : class Vector
location: class TableConnection1
Vector row;
^
TableConnection1.java:53: cannot find symbol
symbol : class Vector
location: class TableConnection1
row = new Vector(columnCount);
^
TableConnection1.java:93: cannot find symbol
symbol : class SQLException
location: class TableConnection1
catch (SQLException ex)
^
12 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
I don't know what's the problem.
Thank's so much for the help.
P.D. sorry for my english, I'm mexican.
02-16-2009, 08:22 AM
Hack
Split from an old thread into its own thread
02-18-2009, 02:10 PM
ajhampson
Table Connection Errors
Looks like you're missing an import or two.
Code:
import java.sql.*
should clear the SQL related ones.
Also keep in mind that your JDBC driver jar file must be in your classpath or you'll get more errors. That would be both compile and runtime classpaths, by the way.
Generally speaking, if javac is telling you it can't find something, it's usually either a classpath or import problem.
BTW, your English is just fine; certainly better than my Spanish! :)