设计一个函数getInfo查询最大id所对应的内容 public String getInfo(String max) 

Date date = new Date(); 
System.out.println(date.toString()); 
boolean flag; 
String str = null; 
try { 
flag = this.ConnData(); 
if(flag == true) 

System.out.println("chenggong"); 

else 

System.out.println("shibai"); 

} catch (Exception ex) { 
System.err.println(ex.getMessage()); 

String m_bean; 
try{ 
System.out.println(this.getMaxId()); 
m_bean = this.searchByID(this.getMaxId()); 
str = m_bean; 
System.out.println(str); 
} catch (Exception ex) { 
System.err.println(ex.getMessage()); 
} this.close(); 
return str; 
} 调用上面函数 把最大id内容写入指定表的字段中 import java.sql.*; 
public class tcdata { 
public static void main(String args[]) { 
Connection con; 
String driver; 
String url; 
String str = null; 
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; 
url= "jdbc:microsoft:sqlserver://localhost:1433;databaseName=TCsms"; 
try{ 
Class.forName(driver); 
con = DriverManager.getConnection(url,"sa","cmcc123"); 
TC12580 t1 = new TC12580(); 
t1.getInfo(str); 
String strSql = "insert into Tc_Content(TServiceCode,TCode,TConent,TStatus,TDate) " + 
"values('0099','','" + t1 + "','','')"; 
PreparedStatement pstmt=con.prepareStatement(strSql); 
pstmt.executeUpdate(); 
}catch(Exception e) 

e.printStackTrace(); 



各位大虾帮我看下这段调用TC12580中函数的代码对么 
整了半天检查不出为什么,插入的内容不对
这个代码不太全 主要是想知道 
是函数设计的问题还是调用时候的语法问题啊

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【vamvin_55】截止到2008-08-01 11:15:39的历史汇总数据(不包括此帖):
    发帖的总数量:9                        发帖的总分数:265                      每贴平均分数:29                       
    回帖的总数量:8                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:9                        结贴的总分数:265                      
    无满意结贴数:2                        无满意结贴分:70                       
    未结的帖子数:0                        未结的总分数:0                        
    结贴的百分比:100.00%               结分的百分比:100.00%                  
    无满意结贴率:22.22 %               无满意结分率:26.42 %                  
    敬礼!

    取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=vamvin_55
      

  2.   

    public String getInfo(String max) 
    能返回你想要的内容?
      

  3.   

    preparedStatement的insert语句最好用?来替代,安全一点
    在getInfo()的第一个try-catch的catch block中加个throw new RuntimeException()看下
      

  4.   

    回2楼朋友
    public String getInfo(String max)
    是可以返回内容的
    3楼朋友的方法我有些不太明白
    改了以后应该没什么实质的变化啊
    补充下
    前面的代码是class TC12580中的一段
    后面的程序想调用前面class中的方法
    运行的时候是可以返回内容
    插入数据库的时候就出问题了
    插进去的内容不对
    我初步怀疑可能是调用的时候哪没写对吧...
      

  5.   

    String strSql = "insert into Tc_Content(TServiceCode,TCode,TConent,TStatus,TDate) " + 
    "values('0099','','" + t1 + "','','')"; 
    看你的意思,是不是应该把这个SQL语句中的t1改成t1.getInfo(str)
      

  6.   

     String strSql = "insert into Tc_Content(TServiceCode,TCode,TConent,TStatus,TDate) " +
    "values('0099','','" + t1 + "','','')";
    PreparedStatement pstmt=con.prepareStatement(strSql); 
    LZ是初学者吧? 最起码 PreparedStatement  对象 从conn中获取实例的参数也不对啊
    首先 最好是用 ? 占位符,另外,你是想在数据库中添加 日期 对象是吗?
    日期对象也不能为 ‘’ 啊 如果你不想添加日期 ,那也要给它一个 NULL 吧
    其它的要看你的错误提示信息了
    完毕