Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,168 members, 7,957,369 topics. Date: Tuesday, 24 September 2024 at 11:38 AM |
Nairaland Forum / Science/Technology / Programming / Help Me Fix My Java Login Code Error (1301 Views)
I Need Serious Help On My Java Program / Pls How Do I Run My Java Program Using Jdk / Help I Need To Test My Java Application On My Laptop (2) (3) (4)
Help Me Fix My Java Login Code Error by jboy01(m): 6:16pm On Oct 17, 2013 |
import java.sql.*; import java.util.logging.Level; import java.util.logging.Logger; /** *UpDate database * @author Latyf */ public class UpdateDatabase { private String firstName; private String midName; private String lastName; private String sex; private String marStatus; private String birthDate; private String state; private String localGov; private String homeAdd; private String officeAdd; private String phoneNumb; private String email; public UpdateDatabase(String fN,String mN,String lN,String s,String mS,String bD,String st,String lG, String hA, String oA,String pN, String em) { firstName=fN; midName=mN; lastName=lN; sex=s; marStatus=mS; birthDate=bD; state=st; localGov=lG; homeAdd=hA; officeAdd=oA; phoneNumb=pN; email=em; } public void updateDatatable() throws ClassNotFoundException { Connection conn; PreparedStatement statement=null; try { //String myDriver="com.mysql.jdbc.Driver"; //Class.forName(myDriver); conn=DriverManager.getConnection("jdbc:mysql://localhost/add_book","root","" // statement=conn.prepareStatement("INSERT INTO data_book(`first_name`, `middle_name`," // + " `last_name`, `sex`, `mar_status`, `birth_date`, `state`, `local_gov`, `home_add`, `office_add`," // + " `phone_no`, `email`) VALUES (" + firstName + "," + midName + "," + lastName + "," + sex + "," + marStatus + "," + birthDate + "," // + state + "," + localGov + "," + homeAdd + "," + officeAdd + "," + phoneNumb + "," + email + "" statement=conn.prepareStatement("INSERT INTO data_book(`first_name`, `middle_name`,`last_name`, `sex`, `mar_status`, `birth_date`, `state`," + " `local_gov`, `home_add`, `office_add`, `phone_no`, `email`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)" statement.setString(1,firstName); statement.setString(2,midName); statement.setString(3,lastName); statement.setString(4,sex); statement.setString(5,marStatus); statement.setString(6,birthDate); statement.setString(7,state); statement.setString(8,localGov); statement.setString(9,homeAdd); statement.setString(10,officeAdd); statement.setString(11,phoneNumb); statement.setString(12,email); statement.executeUpdate(); } catch (SQLException ex) { Logger.getLogger(UpdateDatabase.class.getName()).log(Level.SEVERE, null, ex); //System.out.println("here 1" } //MYSQL QUERY } |
Re: Help Me Fix My Java Login Code Error by jboy01(m): 6:19pm On Oct 17, 2013 |
This is d error i get: Oct 17, 2013 6:17:11 PM addressbook.UpdateDatabase updateDatatable SEVERE: null com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'state' at row 1 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3607) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3541) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2002) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2163) at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2624) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2127) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2427) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2345) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2330) at addressbook.UpdateDatabase.updateDatatable(UpdateDatabase.java:73) |
Re: Help Me Fix My Java Login Code Error by ToyinDipo(m): 8:31pm On Oct 17, 2013 |
I think you are trying to insert into a column, a value larger than it can contain, based on your table definition. 1 Like |
Re: Help Me Fix My Java Login Code Error by ogunayo: 10:35am On Oct 18, 2013 |
Is this a login problem or insert problem ? |
Re: Help Me Fix My Java Login Code Error by jboy01(m): 4:29pm On Oct 18, 2013 |
ogunayo: Is this a login problem or insert problem ?sorry bro, its an insertion problem |
Re: Help Me Fix My Java Login Code Error by jboy01(m): 4:33pm On Oct 18, 2013 |
thank you all for the reply. i have fix the bug, the problem occur when i was passing the parameters from the main class to the constructor in the database class, i mistakely interchange state position for date of birth. |
Re: Help Me Fix My Java Login Code Error by javadoctor(m): 6:24pm On Oct 18, 2013 |
@Toyindipo is very correct,u re tryin 2insert into prolly a mysql varchar column Wich throws the exception. Any programmer can understnd dis error. I gues dat solves. Inbetween; why are u not using jpa persistence for ur database transactions? . It saves u al this boiler plates codes u re writing here . Cheers. |
Re: Help Me Fix My Java Login Code Error by loyanet(m): 10:41pm On Oct 21, 2013 |
jboy01: import java.sql.*; |
(1) (Reply)
Teacher Gave Me Punishment To Write 5000 Times The Following Line / Help Designing A Database Table For A Cbt App / Photo Of The Day(for Laughs Only)
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22 |