设计一个函数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中函数的代码对么
整了半天检查不出为什么,插入的内容不对
这个代码不太全 主要是想知道
是函数设计的问题还是调用时候的语法问题啊
{
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中函数的代码对么
整了半天检查不出为什么,插入的内容不对
这个代码不太全 主要是想知道
是函数设计的问题还是调用时候的语法问题啊
解决方案 »
- java中如何根据容器中的对象的某个属性重新存放在另一个容器中
- 编写一个类,包括一个字符串变量,在定义处将期初始化.另一个字符串变量由构建器初始化.说明这两种方法的区别?
- 汉语乱码问题
- 求助,ZIP文件直接读取内容
- 判断a是不是B的实例??
- 一个不错的java书籍下载网站,不敢独享
- 还是JAVA环境变量设置问题,请各位高手进来帮忙一个,谢谢了~\^O^/
- 请帮忙,我的WINDOWS98,开始中的"运行"被恶意删除,请问,怎么还原?谢谢
- 什么叫“删除一个元素,就必须移到另一个元素“?
- 用Java写一个Server端,有多大实用价值?
- java调用ntdll.dll中的函数
- hashtable 和 iterator
楼主【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
能返回你想要的内容?
在getInfo()的第一个try-catch的catch block中加个throw new RuntimeException()看下
public String getInfo(String max)
是可以返回内容的
3楼朋友的方法我有些不太明白
改了以后应该没什么实质的变化啊
补充下
前面的代码是class TC12580中的一段
后面的程序想调用前面class中的方法
运行的时候是可以返回内容
插入数据库的时候就出问题了
插进去的内容不对
我初步怀疑可能是调用的时候哪没写对吧...
"values('0099','','" + t1 + "','','')";
看你的意思,是不是应该把这个SQL语句中的t1改成t1.getInfo(str)
"values('0099','','" + t1 + "','','')";
PreparedStatement pstmt=con.prepareStatement(strSql); LZ是初学者吧? 最起码 PreparedStatement 对象 从conn中获取实例的参数也不对啊
首先 最好是用 ? 占位符,另外,你是想在数据库中添加 日期 对象是吗?
日期对象也不能为 ‘’ 啊 如果你不想添加日期 ,那也要给它一个 NULL 吧
其它的要看你的错误提示信息了
完毕