Results 1 to 6 of 6
- 09-23-2011, 05:09 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Problem with jtable, mysql and a JAR file
Hello:
I have a program that i can run ok inside de eclipse IDE.
This program connect to an mysql database and show the result in a jtable.
But when i export this program to a JAR file, when i execute the program, do nothing.
Can anyone help me with this code.
Thanks
Java Code:import java.awt.Component; import java.sql.*; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; /** * Clase de prueba de conexión con una base de datos MySQL */ @SuppressWarnings("unused") public class PruebaMySQL extends AbstractTableModel{ /** * */ private static final long serialVersionUID = 1L; Vector<String[]> cache; int colCount; public PruebaMySQL() { DefaultTableModel d = new DefaultTableModel(); String []headers; cache = new Vector<String[]>(); try { DriverManager.registerDriver(new org.gjt.mm.mysql.Driver()); Connection conexion = DriverManager.getConnection ( "jdbc:mysql://localhost/pablo","root", "bauca"); Statement s = conexion.createStatement(); ResultSet rs = s.executeQuery ("select * from clientes"); ResultSetMetaData meta = rs.getMetaData(); colCount = meta.getColumnCount(); headers = new String[colCount]; for (int h = 1; h <= colCount; h++) { headers[h - 1] = meta.getColumnName(h); } while (rs.next()) { String[] record = new String[colCount]; for (int i = 0; i < colCount; i++) { record[i] = rs.getString(i + 1); } cache.addElement(record); } fireTableChanged(null); System.out.println(colCount); // Se recorre el ResultSet, mostrando por pantalla los resultados. /* while (rs.next()) { System.out.println (rs.getInt ("Id") + " " + rs.getString (2)+ " " + rs.getString(3)+ " " + rs.getString(4) + " " + rs.getString(5) + " " + rs.getString(6)); } */ conexion.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { JTable t = new JTable(new PruebaMySQL()); JFrame f = new JFrame(); JLabel l = new JLabel("a"); JScrollPane s = new JScrollPane(t); f.getContentPane().add(s); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(500,500); f.setVisible(true); } @Override public int getColumnCount() { // TODO Auto-generated method stub return colCount; } @Override public int getRowCount() { // TODO Auto-generated method stub return cache.size(); } @Override public Object getValueAt(int row, int col) { // TODO Auto-generated method stub return ((String[]) cache.elementAt(row))[col]; } }
- 09-23-2011, 05:37 PM #2
Re: Problem with jtable, mysql and a JAR file
)) I guess you have a ClassNotFound exception. When you run this app in eclipse it makes classpath itself, but if you want to run this app without IDE you must do manifest file where point all libraries which you use.
Skype: petrarsentev
http://TrackStudio.com
- 09-23-2011, 05:52 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: Problem with jtable, mysql and a JAR file
Ok.
I am a beginer, can you tell me how to do that ?
thanks
-
Re: Problem with jtable, mysql and a JAR file
You haven't told us of any error messages that you're receiving. You also haven't shown us the results of any attempts to debug this yourself with println statements or log statements to a file.
- 09-23-2011, 05:57 PM #5
Member
- Join Date
- Sep 2011
- Posts
- 5
- Rep Power
- 0
Re: Problem with jtable, mysql and a JAR file
Hello
Y run the jar in console and i have this error,
Exception in thread "main" java.lang.NoClassDefFoundError: org/gjt/mm/mysql
er
at PruebaMySQL.<init>(PruebaMySQL.java:34)
at PruebaMySQL.main(PruebaMySQL.java:80)
Caused by: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
C:\Documents and Settings\Romulo Lerman\Escritorio>java -jar pauli.jar
C:\Documents and Settings\Romulo Lerman\Escritorio>java -jar tabla.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/gjt/mm/mysql
er
at PruebaMySQL.<init>(PruebaMySQL.java:34)
at PruebaMySQL.main(PruebaMySQL.java:80)
Caused by: java.lang.ClassNotFoundException: org.gjt.mm.mysql.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
- 09-23-2011, 06:02 PM #6
Re: Problem with jtable, mysql and a JAR file
)) Oh Yeah I was right. read about that Adding Classes to the JAR File's Classpath (The Java™ Tutorials > Deployment > Packaging Programs in JAR Files)
Skype: petrarsentev
http://TrackStudio.com
Similar Threads
-
jtable mysql search
By hash004 in forum New To JavaReplies: 8Last Post: 09-08-2011, 06:05 PM -
Jtable and Mysql
By ehsan in forum AWT / SwingReplies: 1Last Post: 08-13-2011, 10:14 PM -
import Excel file into Mysql DB via Java unknown problem
By black300 in forum JDBCReplies: 0Last Post: 04-02-2011, 10:22 AM -
JTable, Vector, File, Problem.
By ocean in forum New To JavaReplies: 4Last Post: 11-06-2009, 07:51 AM -
Problem with jTable that is binded with a table in MySQL Database
By rajkenneth in forum NetBeansReplies: 0Last Post: 03-29-2008, 03:36 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks