Mam cos takiego
/*
- NewJFrame.java
- Created on 13 czerwiec 2006, 16:20
*/
package javaapplication4;
import java.awt.;
import java.applet.;
import java.sql.*;
import java.util.Properties;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import Lib.Lib;
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
}
private void xxx(java.awt.event.MouseEvent evt) {
new Lib().configConnection("select * from dzialy");
jTextField1.setText("23");
Table.setValueAt("123",1,0);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTable Table;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
// End of variables declaration
}
package Lib;
import java.sql.*;
import java.util.Properties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import javax.swing.JTextField;
public class Lib {
protected Connection con;
protected String driverName;
Statement stmt = null;
ResultSet result = null;
Integer i;
public Connection getCon() {
return con;
}
public void setCon(Connection con) {
this.con = con;
}
public void configConnection(String selectSQL) {
i = 1;
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
try {
String url = "jdbc:mysql://localhost/Agencja reklamowa";
Properties prop = new Properties();
prop.setProperty("user","");
prop.setProperty("password","");
this.con = DriverManager.getConnection(url, prop);
stmt = this.con.createStatement();
ResultSet res = stmt.executeQuery(selectSQL);
while (res.next()){
jTextField1.setText("23");
Table.setValueAt(res.getObject(1),i,0);
Table.setValueAt(res.getObject(2),i,1);
Table.setValueAt(res.getObject(3),i,2);
i++;
}
con.close();
stmt.close();
res.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
Rzecz w tym że chciałbym się odwołać do pola jTextField1 i Table (jTextField1.setText("23");
Table.setValueAt(res.getObject(1),i,0);
Table.setValueAt(res.getObject(2),i,1);
Table.setValueAt(res.getObject(3),i,2);)
z package Lib ale nie działa, wywala błąd. Czy wie ktoś jak to poprawić ?