+1 vote
178 views

hi,

when i try to insert string into ms access from java,it is working successfully..but when i try to insert integer into access it shows error..can any give the solution..

my java program..


import java.sql.*;

public class insert {
public static void main(String args[])
{
    try
    {
    Connection con;
    con=DriverManager.getConnection("jdbc:ucanaccess://F:\\gypsii\\mine.accdb");
    Statement s=con.createStatement();
    s.executeUpdate("insert into one values('ram',101,'per',45)");
    System.out.println("sucessfully updated");
    }
    catch(Exception e)
    {
        System.out.println(e.getMessage());
    }
}
}

 

i am getting following error..

UCAExc:::3.0.3.1 data exception: invalid character value for cast

asked Feb 19, 2016 in Computer Science - IT by gypsiii
edited Feb 19, 2016 by slow_learner | 178 views
please specify datatypes for columns used..if you have datatype for string ,while inserting use " (double quotes) instead of ' quotes
in access 2013...

mytable....

one

name-  short text
id - Number
address- short text
mobile - Number

we can not use double quotes for string on this line
 s.executeUpdate("insert into one values('ram',101,'per',45)");

and

when all data types are string it working sucessfully..but when we try to deal with Number it encounter the error..
try :
 s.executeUpdate("insert into one values('ram','101','per','45')");
yaa already tried..not working........
give a try on :
s.executeUpdate("insert into one (name,id,address,mobile) values('ram',101,'per',45)");

1 Answer

0 votes
Selected Ans.

Rewrite your query as :

s.executeUpdate("insert into one (name,id,address,mobile) values('ram',101,'per',45)");
answered Feb 19, 2016 by slow_learner
selected Feb 19, 2016 by gypsiii
working...wat a simple logic g...