我尝试使用JDBC使用以下方法使用PreparedStatement插入userId(int)和userName(String):
public boolean saveUser(int userId, String userName){
boolean saveStatus = false;
try {
connection.setAutoCommit(true);
String sql = "insert into testtable values(?,?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setInt(1, userId);
statement.setString(2, userName);
saveStatus = statement.execute(sql);
} catch (SQLException e) {
e.printStackTrace();
}finally{
Connector.closeConnections();
}
return saveStatus;
}
Run Code Online (Sandbox Code Playgroud)
我得到以下stacktrace:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near '?,?)' at line 1
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在尝试为两列的组合实现唯一约束.我正在运行oracle 11g.
具体来说,我有两列A和B.
我有一排如下
A B
1 2
Run Code Online (Sandbox Code Playgroud)
然后我希望插入时以下组合失败
A B
1 2
2 1
Run Code Online (Sandbox Code Playgroud)
这可能是通过Oracle中的唯一索引实现的吗?