import java.sql.*;
class ProductAddPreparedStatement
{
		public static void main(String arg[])
		{    
            		Connection con; PreparedStatement st; 
			try
			{    
                		System.out.println("正在连接数据库");
				Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
				con=DriverManager.getConnection("jdbc:odbc:aaa","sa","");
				System.out.println("Already Connected to database");
				st=con.prepareStatement("insert into product(ProductID,ProductName,ProductPrice,Discount)values(?,?,?,?)");
				st.setInt(1,8);
				st.setString(2,"ad");
				st.setInt(3,54);
				st.setInt(4,2);
				st.executeUpdate();
				System.out.println("已经写入了一行:"); 
				st.close();
				con.close();
			}
			catch(ClassNotFoundException e){System.out.println(e.toString());}
			catch(SQLException e){System.out.println(e.toString());}
	}
}
