编译器提示:未报告的异常 java.lang.Exception;必须对其进行捕捉或声明以便抛出
就是这句报错:sqlChange.insert(n,data,destination,seat,price,cheapP);insert()函数如下:publicstat...
就是这句报错: sqlChange.insert(n,data, destination, seat, price, cheapP);
insert()函数如下:
public static void insert(int n,String data,String destination,int seat,int price,int cheapP) throws Exception{
Connection conn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
conn =DriverManager.getConnection("Jdbc:Odbc:Sqlserver","sa","");
// Statement stmt = conn.createStatement();//只读的结果集
Statement stmt2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);//可更新的结果集
PreparedStatement ps = conn.prepareStatement( "INSERT INTO 航班班次 VALUES(?,?,?,?,?,?)");
ps.setInt(1,n);
ps.setString(2,data);
ps.setString(3,destination);
ps.setInt(4,seat);
ps.setInt(5,price);
ps.setInt(6,cheapP);
ps.executeUpdate();
//第五步:关闭连接
conn.close();
} 展开
insert()函数如下:
public static void insert(int n,String data,String destination,int seat,int price,int cheapP) throws Exception{
Connection conn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// DriverManager.registerDriver(new sun.jdbc.odbc.JdbcOdbcDriver());
conn =DriverManager.getConnection("Jdbc:Odbc:Sqlserver","sa","");
// Statement stmt = conn.createStatement();//只读的结果集
Statement stmt2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);//可更新的结果集
PreparedStatement ps = conn.prepareStatement( "INSERT INTO 航班班次 VALUES(?,?,?,?,?,?)");
ps.setInt(1,n);
ps.setString(2,data);
ps.setString(3,destination);
ps.setInt(4,seat);
ps.setInt(5,price);
ps.setInt(6,cheapP);
ps.executeUpdate();
//第五步:关闭连接
conn.close();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |