jdbc中使用updateXXX方法的疑问?急!急!急! 说你的 CON是关闭的a cloned connection --一个关闭的连接 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 can't start a cloned connection while in manual transaction mode closed?//JDBC-数据库的更新方式.txt//:SqlServerJdbcDirect.javaimport java.sql.*;public class SqlServerJdbcDirect { public static void main(String[] args){ String dbUrl="jdbc:microsoft:sqlserver://tsc:1433;user=sa;password=mdzly109;DatabaseName=NorthWind"; Connection con; Statement stmt; String user; ResultSet result=null; try{ //使用MS提供的JDBC类。需要下载SQL Server的JDBC库。 Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); }catch(ClassNotFoundException ex){ ex.printStackTrace(); } try{ //简单的使用 con = DriverManager.getConnection(dbUrl); stmt=con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); result=stmt.executeQuery("select * from Region"); while (result.next()){ System.out.println(result.getInt(1)+" "+result.getString(2)); //由于该表的第一个字段是自动增量,不许更新,否则有异常 //SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can not update, //the specified column is not writable. //result.updateInt(1,result.getInt(1)+1); //更新的一个示例 result.updateString(2, "tangshancheng"+result.getString(2)); result.updateRow(); // updates the row in the data source } result.close(); con.close(); }catch(SQLException ex){ System.err.println("SQLException: " + ex.getMessage()); } }} 很高兴看到你们的回复,我想我程序的所有与你所提供的简单例子不同的地方就是我在对某个修改的value是从另一个数据库中取来的,我马上在做一下普通的试验,看能否通过!做个解释:cloned的中文是克隆,也就是复制的意思! 谢谢各位,我已经解决!原来是我把autocommit 设为false的缘故! 上传文件并split后保存到表的问题 一个Math.random的问题,求解 我现在想把一个字符串数组如list[20]组合成一个大的字符串,请问怎么做 一个和tomcat 相关的问题 高分求教5个JAVA题,解决即给分!! 两个小问题,关于补码和weblogic+jb的,50分,马上结,请赐教! 这个是什么错误? 类String. split 实现,请帮忙看看case 是否全,代码哪里可以优化。 jbuilder的数据库操作问题(oracle9i) applet密码验证的问题? 100分求JBuilder8.0中文版和注册码的下载地址. jbuilder8简单问题
closed?
//JDBC-数据库的更新方式.txt//:SqlServerJdbcDirect.java
import java.sql.*;public class SqlServerJdbcDirect {
public static void main(String[] args){
String dbUrl="jdbc:microsoft:sqlserver://tsc:1433;user=sa;password=mdzly109;DatabaseName=NorthWind";
Connection con;
Statement stmt;
String user;
ResultSet result=null;
try{
//使用MS提供的JDBC类。需要下载SQL Server的JDBC库。
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}catch(ClassNotFoundException ex){
ex.printStackTrace();
} try{
//简单的使用
con = DriverManager.getConnection(dbUrl);
stmt=con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
result=stmt.executeQuery("select * from Region");
while (result.next()){
System.out.println(result.getInt(1)+" "+result.getString(2));
//由于该表的第一个字段是自动增量,不许更新,否则有异常
//SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Can not update,
//the specified column is not writable.
//result.updateInt(1,result.getInt(1)+1);
//更新的一个示例
result.updateString(2, "tangshancheng"+result.getString(2));
result.updateRow(); // updates the row in the data source
}
result.close();
con.close();
}catch(SQLException ex){
System.err.println("SQLException: " + ex.getMessage());
}
}
}