主题:跟数据库连接的一个问题~~
charliehy
[专家分:30] 发布于 2006-04-26 15:47:00
我在书上打了这样的一个例子,小弟初学在Netbeans下运行,不知道段程序是应该在JSP文件下还是应该写在JAVA文件下
package cha1_1;
import java.sql.*;
/**
*
* @author HAPPY
*/
public class DB1 {
public static void main(String[] args){
String url="jdbc:odbc:accp";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(java.lang.ClassNotFoundException e){}
try{
Connection con=DriverManager.getConnection(url,"sa","sa");
Statement stmt=con.createStatement();
stmt.executeUpdate("update cardInfo set openMoney=130 where customerID=3");
ResultSet rs=stmt.executeQuery("select*from cardInfo");
while(rs.next()){
String r1=rs.getString("customerID");
String r2=rs.getString("openMoney");
System.out.println(r1+""+r2);
}
rs.close();
stmt.close();
con.close();
}catch(SQLException e){
System.out.println("\n***SQLException caught *** \n");
}
}
}
我想应该是该写在JAVA下吧,那为什么不会显示出数据库里面表的更改内容呢。。
菜鸟求助
板凳
charliehy [专家分:30] 发布于 2006-04-26 18:21:00
数据源建了,是建的SQL Server
应该米有啥问题。。。运行后没啥错误,就是不出结果,运行后的结构是这样的:
.......
smallint
Get integer data (SQLGetData), hStmt=47457040, column=2
value=5
Get integer data (SQLGetData), hStmt=47457040, column=3
value=5
Fetching (SQLFetch), hStmt=47457040
Get string data (SQLGetData), hStmt=47457040, column=1, maxLen=257
smallint identity
Get integer data (SQLGetData), hStmt=47457040, column=2
value=5
Fetching (SQLFetch), hStmt=47457040
Get string data (SQLGetData), hStmt=47457040, column=1, maxLen=257
float
Get integer data (SQLGetData), hStmt=47457040, column=2
value=6
Get integer data (SQLGetData), hStmt=47457040, column=3
value=15
Fetching (SQLFetch), hStmt=47457040
Get string data (SQLGetData), hStmt=47457040, column=1, maxLen=257
real
Get integer data (SQLGetData), hStmt=47457040, column=2
value=7
Get integer data (SQLGetData), hStmt=47457040, column=3
value=7
Fetching (SQLFetch), hStmt=47457040
Get string data (SQLGetData), hStmt=47457040, column=1, maxLen=257
datetime
Get integer data (SQLGetData), hStmt=47457040, column=2
value=11
Get integer data (SQLGetData), hStmt=47457040, column=3
value=23
Fetching (SQLFetch), hStmt=47457040
Get string data (SQLGetData), hStmt=47457040, column=1, maxLen=257
smalldatetime
Get integer data (SQLGetData), hStmt=47457040, column=2
value=11
Fetching (SQLFetch), hStmt=47457040
Get string data (SQLGetData), hStmt=47457040, column=1, maxLen=257
varchar
Get integer data (SQLGetData), hStmt=47457040, column=2
value=12
Get integer data (SQLGetData), hStmt=47457040, column=3
value=8000
Fetching (SQLFetch), hStmt=47457040
End of result set (SQL_NO_DATA)
*ResultSet.close
Free statement (SQLFreeStmt), hStmt=47457040, fOption=1
*ResultSet has been closed
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=44
int value=23
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=168
int value=8065
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=151
int value=73695
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=145
int value=69599
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=121
int value=15
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=120
int value=2
Get connection info (SQLGetInfo), hDbc=47453000, fInfoType=153
int value=1
getConnection returning driver[className=sun.jdbc.odbc.JdbcOdbcDriver,sun.jdbc.odbc.JdbcOdbcDriver@190d11]
*Connection.createStatement
Allocating Statement Handle (SQLAllocStmt), hDbc=47453000
hStmt=47457040
Setting statement option (SQLSetStmtOption), hStmt=47457040, fOption=6, vParam=0
Setting statement option (SQLSetStmtOption), hStmt=47457040, fOption=7, vParam=1
Registering Statement sun.jdbc.odbc.JdbcOdbcStatement@de6f34
*Statement.executeUpdate (update cardInfo set openMoney=130 where customerID=3)
*Statement.execute (update cardInfo set openMoney=130 where customerID=3)
Free statement (SQLFreeStmt), hStmt=47457040, fOption=0
Executing (SQLExecDirect), hStmt=47457040, szSqlStr=update cardInfo set openMoney=130 where customerID=3
RETCODE = -1
ERROR - Generating SQLException...
SQLException: SQLState(S0002) vendor code(208)
***SQLException caught ***
生成成功(总时间:0 秒)