Use variables declared in other class
<p>Okay I'm kinda stuck at a point where I have to ask</p>

<p>I have 2 classes called main and dbconnect</p>

<p>In my dbconnect I have all the neccesary methods to connect to a database and in my main class  I created the GUI, but problem is I declared variables in my main ( because they are represented by textboxes) and now want to use them in my dbconnect class</p>

<p>my dbconnect class looks like follow</p>

<pre><code>import javax.swing.*;
import java.sql.*;

public class DBCONNECT
{
Connection conn;
public void connect()
{

    try
    {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        conn = DriverManager.getConnection("jdbc:odbc:DriverConn");
    }
    catch(Exception se)
    {
        JOptionPane.showMessageDialog(null, "Error: Could not load driver " + se.getMessage());
    }
}
public void dissconect()
{
    try
    {
        conn.close();
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, "Error : Could not close Database " + e.getMessage());
    }
}
public void writeToDB()
{
    try
    {
        MAIN main = new MAIN();
        Statement st = conn.createStatement();
        String command1 = ("INSERT INTO Drivers (IDNumber, FirstName, LastName) VALUES" + drivID + FName + LName);
        String command2 = "INSERT INTO Offences(IDNumber, SpeedLimit, DriverSpeed, SeatBelt, DrunkenDriving, DriversLicense) VALUES" + drivID + intspeed + intDSpeed + strSeat + strDrunk + strLicense;
        String command3 = "INSERT INTO DriverPoints(IDNumber, Points) VALUES" + drivID + intpoints;
    }
}
public ResultSet select(String sql)
{
    try
    {
        Statement st = conn.createStatement();
        return st.executeQuery(sql);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, "Error: Could not read from database");
    }
    return null;
}
public int change (String sql)
{
    try
    {
        Statement st = conn.createStatement();
        return st.executeUpdate(sql);
    }
    catch(Exception e)
    {
        JOptionPane.showMessageDialog(null, "Error: Could not Update Database");
    }
    return -1;
}
}
</code></pre>

<p>can someone please help?</p>
