Question
(Java) How can I fix this SLQ error? Is something wrong with the date perhaps? (I put line 23 in bold) UCAExc:::4.0.3 data exception: invalid
(Java) How can I fix this SLQ error? Is something wrong with the date perhaps? (I put line 23 in bold)
UCAExc:::4.0.3 data exception: invalid character value for cast
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:230)
at Week10.SpidermanIns.main(SpidermanIns.java:23)
Caused by: java.sql.SQLDataException: data exception: invalid character value for cast
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCUtil.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
at net.ucanaccess.jdbc.ExecuteUpdate.executeWrapped(ExecuteUpdate.java:65)
at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:264)
at net.ucanaccess.jdbc.ExecuteUpdate.execute(ExecuteUpdate.java:48)
at net.ucanaccess.jdbc.UcanaccessStatement.executeUpdate(UcanaccessStatement.java:228)
... 1 more
Caused by: org.hsqldb.HsqlException: data exception: invalid character value for cast
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.Scanner.convertToNumber(Unknown Source)
at org.hsqldb.types.NumberType.convertToType(Unknown Source)
at org.hsqldb.StatementDML.getInsertData(Unknown Source)
at org.hsqldb.StatementInsert.getResult(Unknown Source)
at org.hsqldb.StatementDMQL.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 7 more
package Week10;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class SpidermanIns
{
public static void main(String[] args)
{
String url = "jdbc:ucanaccess://C:/Users/nkman/Documents/ComicBookStore.accdb"; //connects to Access File
Connection con;
Statement stmt;
String query = "select * from ComicInventory "; //selects database
try
{
con = DriverManager.getConnection(url, "", "");
stmt = con.createStatement();
stmt.executeUpdate("insert into ComicInventory " + "values('Amazing SM', '89', '10/1/70', 'Doc Ock Lives', '$6.50', 'No')");
stmt.executeUpdate("insert into ComicInventory " + "values('Spectacular SM', '92', '7/1/84', 'What Is The Answer', '$4.50', 'No')");
stmt.executeUpdate("insert into ComicInventory " + "values('Web Of SM', '89', '10/1/70', 'Doc Ock Lives', '$6.50', 'No')");
stmt.executeUpdate("insert into ComicInventory " + "values('Amazing SM', '89', '10/1/70', 'Doc Ock Lives', '$6.50', 'No')");
ResultSet rs = stmt.executeQuery(query);
System.out.println("ComicInventory");
System.out.println("\tComicName\tIssueNumber\tIssueDate\tIssueName\tIssueValue\tMintCondition"); //prints columns
while (rs.next())
{
String comicname = rs.getString("ComicName"); //these are used to print out values in output
int issuenumber = rs.getInt("IssueNumber");
int issuedate = rs.getInt("IssueDate");
String issuename = rs.getString("IssueName");
int issuevalue = rs.getInt("IssueValue");
String mintcondition = rs.getString("MintCondition");
System.out.println( comicname + " " + issuenumber + " " + issuedate + " " + issuename
+ " " + issuevalue + " " + mintcondition);
}
stmt.close();
con.close();
System.exit(0);
}
catch(SQLException ex)
{
System.out.println("SQLException");
System.out.println(ex.getMessage());
ex.printStackTrace();
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started