Connecting netbeans (JAVA) to MYSQL -


the problem when run code, answer col12 instead of getting columns data getting in mysql workbench. need same values. when use query "delete test col1 = 2;" in netbeans error exception.

here code wrote in netbeans.
package sams;

import java.sql.*;   import java.sql.statement; import java.sql.drivermanager;     public class temp_class {    public static void main(string[] args){      try {  string query="select * test";         class.forname("com.mysql.jdbc.driver");         connection con=      drivermanager.getconnection("jdbc:mysql://localhost/javaproject", "root",  "19881990");         statement st=con.createstatement();         resultset rs=st.executequery(query);         rs.next();         string sname= rs.getstring(2);  system.out.println(sname); con.close();     } catch (exception e) {              system.out.println("error");        }       }    } 

i have made table test in mysql workbench, columns="col1, col2, col3" values="1, col11, col12" , "2, col21, col22";

this code use delete value in db. . . getting error exception.

public static void main(string[] args){      try {           string deletesql="delete test col1 = 2";          class.forname("com.mysql.jdbc.driver");         connection con= drivermanager.getconnection("jdbc:mysql://localhost/javaproject", "root", "19881990");         statement st=con.createstatement();         resultset rs=st.executequery(select);          statement ds=con.createstatement();         resultset dsrow=ds.executequery(deletesql);          dsrow.next();         string ds1= dsrow.getstring(1);         string ds2= dsrow.getstring(2);         string ds3= dsrow.getstring(3);         system.out.println(ds1+" "+ ds2+" "+ds3);          con.close();     } catch (exception e) {          system.out.println("error");      }   } 

string sname= rs.getstring(2); returns 1 column resultset. if want have columns have use:

string sname0= rs.getstring(0); string sname1= rs.getstring(1); string sname2= rs.getstring(2); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -