java.sql.SQLException: [Microsoft][ODBC Microsoft Access 驱动程序] 参数不足,期待是 1。 求解!!! 30
importjava.sql.*;publicclassZm{publicstaticvoidmain(Stringargs[]){Connectioncon=null;...
import java.sql.*;
public class Zm
{
public static void main(String args[])
{
Connection con=null;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(""+e);
}
try
{
double n = 1;
con=DriverManager.getConnection("jdbc:odbc:18","","");
con.setAutoCommit(false);
sql=con.createStatement();
rs=sql.executeQuery("SELECT* FROM shop WHERE number='A001'");
rs.next();
double priceOne=rs.getDouble("price");
System.out.println("事务操作之前的A001的PRICE:"+priceOne);
rs=sql.executeQuery("SELECT* FROM shop WHERE number='B002'");
rs.next();
double priceTwo=rs.getDouble("price");
System.out.println("事务操作之前的B002的PRICE:"+priceTwo);
priceOne=priceOne-n;
priceTwo=priceTwo+n;
sql.executeUpdate("UPDATE shop SET price="+priceOne+"WHERE number='A001'");
sql.executeUpdate("UPDATE shop SET price="+priceTwo+"WHERE number='B002'");
con.commit();
con.setAutoCommit(true);
rs=sql.executeQuery("SELECT* FROM shop WHERE number='A001'");
rs.next();
priceOne=rs.getDouble("price");
System.out.println("事务操作之后的A001的PRICE:"+priceOne);
rs=sql.executeQuery("SELECT* FROM shop WHERE number='B002'");
rs.next();
priceTwo=rs.getDouble("price");
System.out.println("事务操作之后的B002的PRICE:"+priceTwo);
con.close();
}
catch(SQLException e)
{
try
{
con.rollback();
}
catch(SQLException exp){}
System.out.println(e);
}
}
} 展开
public class Zm
{
public static void main(String args[])
{
Connection con=null;
Statement sql;
ResultSet rs;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
System.out.println(""+e);
}
try
{
double n = 1;
con=DriverManager.getConnection("jdbc:odbc:18","","");
con.setAutoCommit(false);
sql=con.createStatement();
rs=sql.executeQuery("SELECT* FROM shop WHERE number='A001'");
rs.next();
double priceOne=rs.getDouble("price");
System.out.println("事务操作之前的A001的PRICE:"+priceOne);
rs=sql.executeQuery("SELECT* FROM shop WHERE number='B002'");
rs.next();
double priceTwo=rs.getDouble("price");
System.out.println("事务操作之前的B002的PRICE:"+priceTwo);
priceOne=priceOne-n;
priceTwo=priceTwo+n;
sql.executeUpdate("UPDATE shop SET price="+priceOne+"WHERE number='A001'");
sql.executeUpdate("UPDATE shop SET price="+priceTwo+"WHERE number='B002'");
con.commit();
con.setAutoCommit(true);
rs=sql.executeQuery("SELECT* FROM shop WHERE number='A001'");
rs.next();
priceOne=rs.getDouble("price");
System.out.println("事务操作之后的A001的PRICE:"+priceOne);
rs=sql.executeQuery("SELECT* FROM shop WHERE number='B002'");
rs.next();
priceTwo=rs.getDouble("price");
System.out.println("事务操作之后的B002的PRICE:"+priceTwo);
con.close();
}
catch(SQLException e)
{
try
{
con.rollback();
}
catch(SQLException exp){}
System.out.println(e);
}
}
} 展开
2个回答
展开全部
这个错误说明的表错 行错 列错 或者语句拼接错误等!
你看看你的sql语句的拼接处where那里和价格是不是连着一块了!
你看看你的sql语句的拼接处where那里和价格是不是连着一块了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询