向Oracle 数据库插入字段时出错!!!
public void insertMessage(String tempID,String message)
{
Connection conn = null;
PreparedStatement stmt = null;
String strSQL = null;
strSQL = "insert into TABLEMQ(ID, MESSAGE) values(?,?)";
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:qiao";
String user="admin";
String password="admin";
conn= DriverManager.getConnection(url,user,password);
stmt = conn.prepareStatement(strSQL);
stmt.setString(1, tempID);
stmt.setString(2, message);
stmt.executeUpdate(strSQL);
stmt.close();
conn.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
数据库为Oracle 9i ,数据库表名为TABLEMQ,包括两个字段:ID (Type 为 VARCHAR2(200)),MESSAGE (Type 为 VARCHAR2(200))
设置断点调试,传入值 tempID = "ID:414d5120514d5f303030303030303020f3f51b4720000e01"
message = "hello world"
执行至stmt.executeUpdate(strSQL);处提示错误为:
java.sql.SQLException: ORA-01008: 并非所有变量都已关联
实在查不出错误,望各位不吝赐教!多谢!
------解决方案--------------------把你这句
stmt.executeUpdate(strSQL);
里面的strSQL去掉,改成
stmt.executeUpdate();
应该是这里了!!!