日期:2014-05-18  浏览次数:20799 次

数据库插入问题!
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); 
确定executeUpdate()里面要带参数吗,

------解决方案--------------------
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.executeUpdate()
stmt.close(); 
conn.close(); 

catch(Exception ex) 

ex.printStackTrace();