//:CreateCoffee.java
//an example using to create and update .
import java.sql.*;
public class CreateCoffee {
public static void main(String args[]) {
String url = "jdbc:odbc:coffees2";
String createString;
String myLogin="yuan";
String myPassword="132440";
Connection con;
Statement stmt;
int[] a={1,102,130,4,16};
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
//using to load driver:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
//using to create:
try {
con = DriverManager.getConnection(url, myLogin, myPassword);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(createString);
stmt.close();
con.close();
}catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
//using to update:
try{
con = DriverManager.getConnection(url, myLogin, myPassword);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
// 允许自动更新
con.setAutoCommit(true); ResultSet re = stmt.executeQuery("select * from coffees2");
re.absolute(2);
re.updateInt(1,a[0]);
re.updateInt(2,a[1]);
re.updateInt(3,a[2]);
re.updateInt(4,a[3]);
re.updateInt(5,a[4]);System.out.println("love");
re.updateRow();
while(re.next()){System.out.println("love");
System.out.println(re.getString(1)+","+ re.getString(2)+","+re.getString(3)+","+re.getString(4));
}
/* String updateString = "UPDATE COFFEES " +
"SET SALES = 90 " ;
stmt.executeUpdate(updateString);System.out.println("love");*/
re.close();
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
/* try{
Thread.currentThread().sleep(5*1000);
}catch(InterruptedException e){}*/
}
}///:~
这是我的程序
但老是有错误:
[Microsoft][.... 驱动程序管理器]:非法的游标状态..
我真是急四了,有答复
必重谢!!!
//an example using to create and update .
import java.sql.*;
public class CreateCoffee {
public static void main(String args[]) {
String url = "jdbc:odbc:coffees2";
String createString;
String myLogin="yuan";
String myPassword="132440";
Connection con;
Statement stmt;
int[] a={1,102,130,4,16};
createString = "create table COFFEES " +
"(COF_NAME VARCHAR(32), " +
"SUP_ID INTEGER, " +
"PRICE FLOAT, " +
"SALES INTEGER, " +
"TOTAL INTEGER)";
//using to load driver:
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch(java.lang.ClassNotFoundException e) {
System.err.print("ClassNotFoundException: ");
System.err.println(e.getMessage());
}
//using to create:
try {
con = DriverManager.getConnection(url, myLogin, myPassword);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt.executeUpdate(createString);
stmt.close();
con.close();
}catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
//using to update:
try{
con = DriverManager.getConnection(url, myLogin, myPassword);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
// 允许自动更新
con.setAutoCommit(true); ResultSet re = stmt.executeQuery("select * from coffees2");
re.absolute(2);
re.updateInt(1,a[0]);
re.updateInt(2,a[1]);
re.updateInt(3,a[2]);
re.updateInt(4,a[3]);
re.updateInt(5,a[4]);System.out.println("love");
re.updateRow();
while(re.next()){System.out.println("love");
System.out.println(re.getString(1)+","+ re.getString(2)+","+re.getString(3)+","+re.getString(4));
}
/* String updateString = "UPDATE COFFEES " +
"SET SALES = 90 " ;
stmt.executeUpdate(updateString);System.out.println("love");*/
re.close();
stmt.close();
con.close();
} catch(SQLException ex) {
System.err.println("SQLException: " + ex.getMessage());
}
/* try{
Thread.currentThread().sleep(5*1000);
}catch(InterruptedException e){}*/
}
}///:~
这是我的程序
但老是有错误:
[Microsoft][.... 驱动程序管理器]:非法的游标状态..
我真是急四了,有答复
必重谢!!!
解决方案 »
- 在eclipse中打包程序为jar文件,放到linux上执行不成功
- 关于一天中时针、分针、秒针的重合问题
- n&n+1|n+2^n+3=?
- 日期字符串,请大家帮忙!谢谢了,
- 如何控制FigureCanvas的滚动条被拖动后的位置?
- 输入输出流问题
- 为何会出现异常,请高手指教!
- 请问如何实现弹出式菜单里面的拷贝,粘贴功能?
- 怎么样连接sql server服务器?(在线)
- jar 的实用问题
- (毕业设计呀,好惨!)两个JBulider应用程序(未打包)之间互相传递信息(比如说用户名,用户密码,登陆日期等等),除了用Socket,还有其他方法吗?(
- 我用JET把我的.class弄成了.exe,在我的机器上可以运行,但环在别的机器上就不行,说是找不到XKRN25013.DLL,则么回事啊?
ResultSet.CONCUR_UPDATABLE);换成:
stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
let me try!!!