I am trying to pass an object as parameter to another class wich contains a SQL connection:
Base class is a swing class where this method is the essential to know for my question:
public void actionPerformed(ActionEvent e)
{
ModelNY mo = new ModelNY();
mo.setPersonID(txtField1.getText());
mo.setFName(txtField2.getText());
mo.setLName(txtField3.getText());
mo.setAdress(txtField4.getText());
mo.setEmail(txtField5.getText());
ConnectToMySQL c = new ConnectToMySQL();
c.connect(mo);
My SQL class recieves this object and I want to get each value an put it inot the 'todo' string:
public void connect(Object o) {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "Mg78QnuE");
String todo = ("INSERT INTO personer(idPersoner, forNavn, etterNavn, adresse, epost) "+
"values ('"+text1+"', '"+text2+"', '"+text3+"', '"+text4+"', '"+text5+"')") ;
Statement statement = conn.createStatement();
statement.executeUpdate(todo);
I want to say something like o.getidpersoner() where I say
"values ('"+text1+"'
as a replacement for text1 you could say.
But I cant say that. I've trid saying o.getClass so that works fine.
Anybody that can help me?