我收到了错误
net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.6数据异常:强制转换的字符值
当我运行此代码时:
package aoa;
import java.sql.*;
public class Aoa {
public static void main(String[] args) {
Connection cn;
Statement st;
ResultSet re;
String ID ="username";
String NAME="password";
try{
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
cn=DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\MUHAMMAD SHAHAB\\STUD1.accdb");
st = cn.createStatement();
String q = "INSERT INTO STUD1 ([Id], [Address]) VALUES (?, ?)";
PreparedStatement pst = cn.prepareStatement (q);
pst.setString(1, "a");
pst.setString(2, "b");
pst.executeUpdate();
System.out.println("inserted"); }
catch(ClassNotFoundException | SQLException e)
{
System.out.println(e);
}
}
}
我做错了什么?
答案 0 :(得分:4)
您将收到错误
net.ucanaccess.jdbc.UcanaccessSQLException:UCAExc ::: 3.0.6数据异常:强制转换的字符值
如果在字符串值无法转换为数字时尝试通过setString
将值分配给数字列。在您的情况下,[Id]列几乎肯定是数字,但
pst.setString(1, "a");
正在尝试分配值" a"到那个专栏," a"无法转换为数字。