Table Connection Errors


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Table Connection Errors

Hybrid View

  1. #1
    Join Date
    Feb 2009
    Posts
    1

    Table Connection Errors

    Hi, the code of my program is the following:

    HTML Code:
    code
    import javax.swing.*;
    import javax.swing.table.*;
    import java.lang.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class TableConnection1 extends JFrame
    {
    	static String  bd = "-*******-";
    	static String usuario = "-******-";
    	static String clave = "-******-";
    	static String url = "jdbc:mysql://localhost/"+bd;
    	
    	public static void main(String args[]) throws Exception
    	{
    		TableConnection1 frame = new TableConnection1();
    		frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
    		frame.pack();
    		frame.setVisible(true);
    	}
    	
    	TableConnection1()
    	{
    		Connection conexion = null;
    		
    		try
    		{
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			conexion = DriverManager.getConnection(url, usuario, clave);
    			
    			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)
    		{
    		}
    	}
    }
    I have problems with this code.

    The errors are the following:

    HTML Code:
     ----jGRASP exec: javac -g C:\tut_java\TableConnection1.java
    
    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.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Split from an old thread into its own thread
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    May 2004
    Posts
    40

    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!

    alan

Similar Threads

  1. Re: (No subject)
    By Joe in forum Database
    Replies: 0
    Last Post: 04-04-2003, 06:13 PM
  2. VB doesn't wait until SQL-query has finished
    By Daniel Teufert in forum VB Classic
    Replies: 2
    Last Post: 04-24-2002, 03:34 PM
  3. Establishing connection attached ODBC table in VB
    By John Nelson in forum VB Classic
    Replies: 2
    Last Post: 05-29-2001, 05:21 PM
  4. Connection Errors (Simple)
    By Neil Konitzer in forum VB Classic
    Replies: 0
    Last Post: 02-08-2001, 10:35 AM
  5. Basic MTS Question - Error 70
    By PZ in forum Enterprise
    Replies: 2
    Last Post: 08-19-2000, 11:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center