dcsimg
How to insert variables in insert into statement mysql (not values).
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Udayakanth_S
Posted On:   Thursday, July 29, 2010 10:51 PM

I am doing a project using Netbeans+mysql. in netbeans I am using forms to get values ( name, age), Problem is how to insert these variables into mysql insert statement using jdbc; mysql table: create table intchar(name varchar(20),age INTEGER); Statement st = con.createStatement(); //tcol1 is textfield name //tcol2 is textfield name // String num1=this.tcol1.getText(); // int num2== Integer.parseInt(this.tcol2.getText()); int val=st.executeUpdate("INSERT INTO intchar ("+ "name,age"+ ") " + "VALUES ("+ "'num1','num2'" + "   More>>

I am doing a project using Netbeans+mysql.

in netbeans I am using forms to get values ( name, age),

Problem is how to insert these variables into mysql insert
statement using jdbc;

mysql table:

create table intchar(name varchar(20),age INTEGER);


Statement st = con.createStatement();


//tcol1 is textfield name

//tcol2 is textfield name

// String num1=this.tcol1.getText();

// int num2== Integer.parseInt(this.tcol2.getText());



int val=st.executeUpdate("INSERT INTO intchar ("+
"name,age"+ ") "

+ "VALUES ("+ "'num1','num2'"

+ ")");


after executing it is showing output.


Unknown column 'num2' in 'field list'

BUILD SUCCESSFUL (total time: 9 seconds)

   <<Less
About | Sitemap | Contact